Commit graph

927 commits

Author SHA1 Message Date
Bjørn Erik Pedersen f4389e48ce
Add some basic security policies with sensible defaults
This ommmit contains some security hardening measures for the Hugo build runtime.

There are some rarely used features in Hugo that would be good to have disabled by default. One example would be the "external helpers".

For `asciidoctor` and some others we use Go's `os/exec` package to start a new process.

These are a predefined set of binary names, all loaded from `PATH` and with a predefined set of arguments. Still, if you don't use `asciidoctor` in your project, you might as well have it turned off.

You can configure your own in the new `security` configuration section, but the defaults are configured to create a minimal amount of site breakage. And if that do happen, you will get clear instructions in the loa about what to do.

The default configuration is listed below. Note that almost all of these options are regular expression _whitelists_ (a string or a slice); the value `none` will block all.

```toml
[security]
  enableInlineShortcodes = false
  [security.exec]
    allow = ['^dart-sass-embedded$', '^go$', '^npx$', '^postcss$']
    osEnv = ['(?i)^(PATH|PATHEXT|APPDATA|TMP|TEMP|TERM)$']

  [security.funcs]
    getenv = ['^HUGO_']

  [security.http]
    methods = ['(?i)GET|POST']
    urls = ['.*']
```
2021-12-16 09:40:22 +01:00
Bjørn Erik Pedersen 3bc6830411 Remove the retries on error in remote resources.Get
Fixes #9271
See  #9259
2021-12-10 11:10:41 +01:00
Bjørn Erik Pedersen e4d6ec94b5 Allow user to handle/ignore errors in resources.Get
In Hugo 0.90.0 we introduced remote support in `resources.Get`.

But with remote resources comes with a higher chance of failing a build (network issues, remote server down etc.).

Before this commit we always failed the build on any unexpected error.

This commit allows the user to check for any error (and potentially fall back to a default local resource):

```htmlbars
{{ $result := resources.Get "https://gohugo.io/img/hugo-logo.png" }}
{{ with $result }}
        {{ if .Err }}
        {{/* log the error, insert a default image etc. *}}
        {{ else }}
        <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
        {{ end }}
{{ end }}
```

Note that the default behaviour is still to fail the build, but we will delay that error until you start using the `Resource`.

Fixes #9529
2021-12-10 11:10:41 +01:00
Joe Mooring 5538507e90 tpl/transform: Optional options for highlight func
Closes #9249
Fixes gohugoio/hugoDocs#63
2021-12-07 11:26:56 +01:00
Paul van Brouwershaven 0eaaa8fee3
Implement XML data support
Example:

```
{{ with resources.Get "https://example.com/rss.xml" | transform.Unmarshal }}
    {{ range .channel.item }}
        <strong>{{ .title | plainify | htmlUnescape }}</strong><br />
        <p>{{ .description | plainify | htmlUnescape }}</p>
        {{ $link := .link | plainify | htmlUnescape }}
        <a href="{{ $link }}">{{ $link }}</a><br />
        <hr>
    {{ end }}
{{ end }}
```

Closes #4470
2021-12-02 17:30:36 +01:00
Bjørn Erik Pedersen 93572e5318 resources: Add timeout to the HTTP request in Get
Workaround for https://github.com/golang/go/issues/49366
2021-12-02 16:11:14 +01:00
Joe Mooring 133e4bfbee Remove empty href element from pagination template
Closes #9149
2021-12-02 09:14:30 +01:00
Paul van Brouwershaven 8aa7257f65
Add remote support to resources.Get
Closes #5255
Supports #9044
2021-11-30 11:49:51 +01:00
Joe Mooring 75a823a36a Add deprecation warning to google_news template
Closes #9172
2021-11-21 11:25:17 +01:00
Joe Mooring 04a3b45db4 Fix description of lang.FormatNumberCustom
It currently refers to itself as a simple alternative, when it should
refer to lang.FormatNumber.
2021-11-01 18:54:43 +01:00
Joe Mooring 0cc39af682 Update Twitter shortcode oEmbed endpoint
The existing endpoint will be retired and removed on November 23, 2021.
References:

- https://twittercommunity.com/t/consolidating-the-oembed-functionality/154690
- https://developer.twitter.com/en/docs/twitter-for-websites/oembed-api#Embedded

This is a backward compatible change.

The existing endpoint requires a single parameter: the id of the tweet.

The new endpoint requires two parameters: the id of the tweet, and the
user with whom it is associated. For the moment, if you supply the wrong
user, the request will be redirected (with a small delay) to the correct
user/id pair. This behavior is undocumented, but we will take advantage
of it as Hugo site authors transition to the new syntax.

{{< tweet 1453110110599868418 >}} --> works, throws warning, deprecate at some point

{{< tweet user="SanDiegoZoo" id="1453110110599868418" >}} --> new syntax

Fixes #8130
2021-11-01 15:51:00 +01:00
Bjørn Erik Pedersen e82cbd746f
tpl/time: Use configured location when date passed to Format is string
Updates #9084
2021-10-30 16:09:38 +02:00
Brad e55466ce70
tpl/path: Add path.Clean
Fixes #8885
2021-10-05 16:15:10 +02:00
Paul Gottschling a864ffe9ac Clarify "precision" in currency format functions
The documentation of the FormatAccounting and FormatCurrency
functions could be clearer in terms of how the precision param
works. This commit makes it more explicit that adding a precision
of < 2 will not format the return values to include fewer decimals.

Resolves #8858
2021-09-22 20:00:30 +02:00
Bjørn Erik Pedersen abd969a670
Revert "tpl/time: Handle nil values in time.AsTime"
This reverts commit 3e11072892.
2021-08-10 13:21:49 +02:00
Bjørn Erik Pedersen 3e11072892
tpl/time: Handle nil values in time.AsTime
Closes #8865
2021-08-09 18:44:35 +02:00
Bjørn Erik Pedersen 9bba9a3a98
parser: Indent TOML tables
Fixes #8850
2021-08-04 11:39:16 +02:00
Salim B d6c8cd7718 Fix lang.FormatPercent description
Successor PR for https://github.com/gohugoio/hugoDocs/pull/1504
2021-08-03 16:56:06 +02:00
Bjørn Erik Pedersen 9ff17c3324
tpl/time: Adjust tests to handle matching local time zones
Closes #8843
2021-08-03 08:54:45 +02:00
Bjørn Erik Pedersen 3a96655592 Reduce binary size vs locale, update to CLDR v36.1
Test building with `go build -ldflags="-s -w"`

Hugo 0.86.2: 46MB
Before this commit: 77MB
After this commit: 54MB

Fixes #8839
Fixes #8841
2021-08-02 19:40:32 +02:00
Bjørn Erik Pedersen 6c70e1f22f Fix error handling for the time func alias
Fixes #8835
2021-08-01 13:39:30 +02:00
Bjørn Erik Pedersen 7907d24ba1
tpl/lang: Add new localized versions of lang.FormatNumber etc.
Fixes #8820
2021-07-29 16:40:06 +02:00
Bjørn Erik Pedersen b5de37ee79
Handle toml.LocalDate and toml.LocalDateTime in front matter
See #8801
2021-07-28 18:02:42 +02:00
Bjørn Erik Pedersen a3701e0931 Switch to go-toml v2
We have been using `go-toml` for language files only. This commit makes it the only TOML library.

It's spec compliant and very fast.

A benchark building a site with 200 pages with TOML front matter:

```bash
name                                  old time/op    new time/op    delta
SiteNew/Regular_TOML_front_matter-16    48.5ms ± 1%    47.1ms ± 1%  -2.85%  (p=0.029 n=4+4)

name                                  old alloc/op   new alloc/op   delta
SiteNew/Regular_TOML_front_matter-16    16.9MB ± 0%    16.7MB ± 0%  -1.56%  (p=0.029 n=4+4)

name                                  old allocs/op  new allocs/op  delta
SiteNew/Regular_TOML_front_matter-16      302k ± 0%      296k ± 0%  -2.20%  (p=0.029 n=4+4)
```

Note that the front matter unmarshaling is only a small part of building a site, so the above is very good.

Fixes #8801
2021-07-28 11:51:13 +02:00
Bjørn Erik Pedersen efa5760db5 Add timezone support for front matter dates without one
Fixes #8810
2021-07-27 19:02:48 +02:00
Bjørn Erik Pedersen a57dda854b Localize time.Format
Fixes #8797
2021-07-27 19:02:48 +02:00
Bjørn Erik Pedersen 022c479551
hugofs: Make FileMeta a struct
This commit started out investigating a `concurrent map read write` issue, ending by replacing the map with a struct.

This is easier to reason about, and it's more effective:

```
name                                  old time/op    new time/op    delta
SiteNew/Regular_Deep_content_tree-16    71.5ms ± 3%    69.4ms ± 5%    ~     (p=0.200 n=4+4)

name                                  old alloc/op   new alloc/op   delta
SiteNew/Regular_Deep_content_tree-16    29.7MB ± 0%    27.9MB ± 0%  -5.82%  (p=0.029 n=4+4)

name                                  old allocs/op  new allocs/op  delta
SiteNew/Regular_Deep_content_tree-16      313k ± 0%      303k ± 0%  -3.35%  (p=0.029 n=4+4)
```

See #8749
2021-07-15 17:14:26 +02:00
Raoul f75f90079a Fix tab selection of disabled items in internal pagination template 2021-07-05 10:30:59 +02:00
Joe Mooring 34e4742f0c Fix date format in schema and opengraph templates
Fixes #8671
2021-06-29 20:20:38 +02:00
Bjørn Erik Pedersen 9096842b04
tpl: Rename err-missing-instagram-accesstoken => error-missing-instagram-accesstoken
To get it in line with the other.
2021-06-18 12:27:37 +02:00
Bjørn Erik Pedersen d392893cd7
Misc config loading fixes
The main motivation behind this is simplicity and correctnes, but the new small config library is also faster:

```
BenchmarkDefaultConfigProvider/Viper-16         	  252418	      4546 ns/op	    2720 B/op	      30 allocs/op
BenchmarkDefaultConfigProvider/Custom-16        	  450756	      2651 ns/op	    1008 B/op	       6 allocs/op
```

Fixes #8633
Fixes #8618
Fixes #8630
Updates #8591
Closes #6680
Closes #5192
2021-06-14 17:00:32 +02:00
Bjørn Erik Pedersen a91cd7652f
docs: Regenerate docs helper 2021-06-08 18:52:38 +02:00
Joe Mooring 73483d0f9e
tpl: Add a terse pagination template variant to improve performance
These calls are equivalent:

{{ template "_internal/pagination.html" . }}
{{ template "_internal/pagination.html" (dict "page" .) }}
{{ template "_internal/pagination.html" (dict "page" . "format" "default") }}

To use an alternate format:

{{ template "_internal/pagination.html" (dict "page" . "format" "terse") }}

Fixes #8599
2021-06-08 10:41:21 +02:00
Bjørn Erik Pedersen 9b5debe4b8 Upgrade Instagram shortcode
Fixes #7879
2021-06-08 10:30:45 +02:00
Bjørn Erik Pedersen f55d2f4376
tpl/fmt: Add erroridf template func
Fixes #8613
2021-06-07 19:11:03 +02:00
Bjørn Erik Pedersen 282f1aa3db
tpl/data: Print response body on HTTP errors
Which makes it easier to debug.
2021-06-07 12:06:27 +02:00
Bjørn Erik Pedersen fcd63de3a5 tpl/data: Misc header improvements, tests, allow multiple headers of same key
Closes #5617
2021-06-06 13:32:12 +02:00
Paul Chamberlain 150d75738b tpl/data: Allows user-defined HTTP headers with getJSON and getCSV
Updates #5617
2021-06-06 13:32:12 +02:00
Joe Mooring 01758f99b9 Add math.Max and math.Min
Closes #8583
2021-05-28 20:38:45 +02:00
Ujjwal Goyal c46fc838a9 tpl: Allow 'Querify' to take lone slice/interface argument
Querify can now take a lone string/interface slice (with string
keys) as a parameter, or multiple string parameters, to build
URL queries.

Querify earlier used 'Dictionary' to add key/value pairs to a
map to build URL queries. Changed to dynamically generate ordered
key/value pairs. Cannot take string slice as key (earlier
possible due to Dictionary).

Added tests and benchmarks for querify.

Closes #6735
2021-05-09 13:14:14 +02:00
Julien Midedji 7a2c10ae60
tpl: Fix countwords to handle special chars
Fixes #8479
2021-05-03 09:10:06 +02:00
Bjørn Erik Pedersen 3cc4fdd6f3 deps: Update getkin/kin-openapi v0.60.0 => v0.61. 2021-04-30 14:27:21 +02:00
Joe Mooring f6745ad358 Remove .Site.Authors from embedded templates
Closes #4458
2021-04-29 17:07:05 +02:00
Bjørn Erik Pedersen e4dc9a82b5 tpl/collections: Fix where on type mismatches
Fixes #8353
2021-04-23 18:06:49 +02:00
Bjørn Erik Pedersen 0d86a32d8f Make the shortcode template lookup for output formats stable
Fixes #7774
2021-04-23 15:04:35 +02:00
Bjørn Erik Pedersen bca40cf0c9 Fix Params case handling in where with slices of structs (e.g. Pages)
Fixes #7009
2021-04-21 19:28:18 +02:00
Joe Mooring 9b34d42bb2 Remove extraneous space from figure shortcode
Fixes #8401
2021-04-15 14:43:32 +02:00
Bjørn Erik Pedersen 5656a908d8
tpl: Remove the FuzzMarkdownify func for now
It has gotten us nothing but "build fails" mail and work we don't have time to follow up on.
2021-03-30 20:57:31 +02:00
Bjørn Erik Pedersen 5e2f128911
Try to fix the fuzz build 2021-03-28 21:42:44 +02:00
Bjørn Erik Pedersen ba1d0051b4 media: Make Type comparable
So we can use it and output.Format as map key etc.

This commit also fixes the media.Type implementation so it does not need to mutate itself to handle different suffixes for the same MIME type, e.g. jpg vs. jpeg.

This means that there are no Suffix or FullSuffix on media.Type anymore.

Fixes #8317
Fixes #8324
2021-03-14 15:21:54 +01:00
Daniel Atwood ba16a14c6e
Add support for Google Analytics v4 2021-03-03 13:30:06 +01:00
Bjørn Erik Pedersen 7f8530039a
tpl: Add method mappings for strings.Contains, strings.ContainsAny
Just to confirm/document the function signature.
2021-02-23 09:36:43 +01:00
Bjørn Erik Pedersen fe77f7434b
tpl: Make the build green again 2021-02-18 18:17:43 +01:00
Bjørn Erik Pedersen c60806550a
tpl: Regenerate internal templates 2021-02-18 17:52:32 +01:00
Daniel Atwood ffd9dac421
tpl: Update date logic of opengraph and schema internal templates
* Fix: updated date logic in opengraph template

* Updated date logic in schema template

* Reformatted opengraph and schema

* Wrapped PublishDate and Lastmod in with
2021-02-18 17:51:32 +01:00
Bjørn Erik Pedersen 9650e56841 tpl: Add temporary patch to fix template data race
Keep this as a separate commit so we can reapply it if needed.

Fixes #7293
2021-02-18 14:11:48 +01:00
Bjørn Erik Pedersen b5485aeae7 Add breaking tests for "map read and map write in templates"
The fix upstream in Go was reverted, so we apply a temporary patch for this in Hugo.

Updates #7293
2021-02-18 14:11:48 +01:00
Bjørn Erik Pedersen ccb822eb5a Pull in latest Go template source 2021-02-18 14:11:48 +01:00
Bjørn Erik Pedersen cf3e077da3 tpl/internal: Synch Go templates fork with Go 1.16dev 2021-02-18 14:11:48 +01:00
susiwen8 bf55afd71f
Fix some humanize issues
Fixes #7912
2021-02-14 18:30:59 +01:00
Jeremy Epstein 4867cd1dea
tpl/embedded: Exclude pages without Permalink from sitemap 2021-02-06 18:30:09 +01:00
Baris Ceviz 35def0ae45
tpl/data: Add default user-agent header for getJSON requests 2021-02-01 09:31:02 +01:00
Aleksandr Demakin ee9c136763 tpl/os: remove 1mb limit for readFile. 2021-01-23 00:39:14 +01:00
Cameron Moore 241b7483ea tpl: Fix race condition in text template baseof
Copy most of the htmltemplate cloning to the textemplate implementation
in the same function.
2021-01-22 19:25:45 +01:00
Cameron Moore 0004a733c8 tpl: Fix metrics hint tracking
When tracking for cache hints, track the same template name as the call
to MeasureSince in Execute.  When referencing a partial "foo", the value
of `n` does not match `templ.Name()` (`partials/foo` versus
`partials/foo.html`).  This was causing hints to go untracked since
there was no existing metric to append the hint to.

Fixes #8125
2021-01-08 20:01:11 +01:00
Cameron Moore 8a26ab0bc5 tpl: Do not return errors in substr for out-of-bounds cases
Most other substr implementations don't error out in out-of-bounds cases
but simply return an empty string (or a value that's printed as an empty
string). We'll follow their lead and not exit template execution.  Allow
the user decide what to do with the empty result.

Fixes #8113
2021-01-08 10:13:10 +01:00
Cameron Moore 788e50ad3a tpl: Add missing test scenario for strings.Substr 2021-01-08 10:13:10 +01:00
Bjørn Erik Pedersen cea1574023
Add Dart Sass support
But note that the Dart Sass Embedded Protocol is still in beta (beta 5), a main release scheduled for Q1 2021.

Fixes #7380
Fixes #8102
2020-12-30 17:32:25 +01:00
Bjørn Erik Pedersen 10ae7c3210
Improve LookPath 2020-12-19 17:03:07 +01:00
Bjørn Erik Pedersen a2d146ec32
tpl: Regenerate templates 2020-12-16 12:20:02 +01:00
Maciej Sawicki d2d493ab5d
tpl: Fix series detection in opengraph
When inside front matter you specified series with spaces,
then the opengraph template wouldn't detect other articles,
because in `.Site.Taxonomies.series` they are stored by 
urlized key.

Example:

```yaml
# in front matter
series:
    - My Series
```

```gohtml
{{/* in a template */}}
{{- $series := index .Site.Taxonomies.series$name }}

{{/* was resolved to */}}
{{- $series := index {'my-series': ...} "MySeries" }}
```
2020-12-16 12:13:30 +01:00
Phil Davis 04b89857e1
all: Fix minor typos 2020-12-16 12:11:32 +01:00
Bjørn Erik Pedersen 718e09ed4b
tpl/internal/go_templates: Revert formatting
Should make future fork synch easier.
2020-12-03 13:47:43 +01:00
Bjørn Erik Pedersen d90e37e0c6 all: Format code with gofumpt
See https://github.com/mvdan/gofumpt
2020-12-03 13:12:58 +01:00
Andrew Zenk 4fc918e02c
tpl: Add title parameter to YouTube shortcode 2020-12-02 12:53:53 +01:00
Cameron Moore 5862fd2a60 tpl: Fix substr when length parameter is zero
When length parameter is zero, always return an empty string.

Updates #7993
2020-12-01 23:20:04 +01:00
Cameron Moore 64789fb5dc tpl: Refactor and fix substr logic
Fix miscalculations when start is negative.  Results should now match
PHP substr.

Fixes #7993
2020-11-28 11:53:46 +01:00
Bjørn Erik Pedersen b298c06e05
deps: Update to Chroma v0.8.2
Closes #7970
2020-11-20 09:30:05 +01:00
AdamKorcz 4f20bf29eb Updated year in header 2020-11-06 13:19:18 +01:00
AdamKorcz 4c613d5d5d Added first fuzzer 2020-11-06 13:19:18 +01:00
Cameron Moore 6d95dc9d74 tpl: Fix reflection bug in merge
Value.Type().Key() must only be called on map values.

Fixes #7899
2020-10-29 19:19:41 +01:00
Bjørn Erik Pedersen fdfa4a5fe6 Allow getJSON errors to be ignored
This change is mostly motivated to get a more stable CI build (we're building the Hugo site there, with Instagram and Twitter shortcodes sometimes failing).

Fixes #7866
2020-10-22 09:09:29 +02:00
Cameron Moore 807db97af8 tpl: Refactor time.AsTime location implementation 2020-10-21 09:49:25 +02:00
Mark Johnson 26eeb29147 tpl: Update Hugo time to support optional [LOCATION] parameter 2020-10-21 09:49:25 +02:00
Cameron Moore 08e4f9ff9c embedded: Always show page number when 5 pages or less
Fixes #7523
2020-10-16 16:16:49 +02:00
Josh Gerdes edc5c4741c tpl: Add Do Not Track (dnt) option to Vimeo shortcode
Added a Vimeo EnableDNT privacy option to the Hugo config. This will enable the Vimeo 'Do Not Track' flag when either Vimeo shortcode tempalte options are used. When enabled, it will force the Vimeo player to be blocked from tracking any session data, including all cookies and stats.

Fixes #7700
2020-10-02 23:02:38 +02:00
Bjørn Erik Pedersen 97987e5c02 langs/i18n: Upgrade to go-i18n v2
Fixes #5242
2020-09-29 17:48:07 +02:00
Evgeny Kuznetsov cd830bb027 tpl: Fix grammar in the new 'requires non-zero' error message 2020-09-14 19:54:48 +02:00
Bjørn Erik Pedersen 4055c12184 Fix some change detection issues on server reloads
* Fix change detection when .GetPage/site.GetPage is used from shortcode
* Fix stale content for GetPage results with short name lookups on server reloads

Fixes #7623
Fixes #7624
Fixes #7625
2020-09-07 21:06:44 +02:00
Cameron Moore cdfd1c99ba tpl: Add limit support to replaceRE
Go stdlib doesn't contain a limited replace in the regexp package, but
we can accomplish the same thing with ReplaceAllStringFunc.

Fixes #7586
2020-08-28 18:57:56 +02:00
Cameron Moore 047af7cfe5 tpl: Extend merge to accept multiple parameters
Fixes #7595
2020-08-28 09:54:51 +02:00
Cameron Moore f9ebaaed1b tpl: Add limit option to replace template function
Updates #7586
2020-08-28 08:55:58 +02:00
Bjørn Erik Pedersen ae63c2b5c9
Fail on partials with return when given none or a zero argument
We need to make a proper fix for this, but it is better with an error than just silently continue.

Fixes #7572
Updates #7528
2020-08-19 10:01:16 +02:00
Kyle Anderson 5f42590144 Remove trailing whitespace and tabs from RSS templates
The rss templates had some tab characters mixed in with the spaces.
Additionally there would end up being trailing whitespace in output
rss feeds, which looks red in git diff.
2020-08-12 09:25:16 +02:00
Joe Mooring bffc4e12fe Revert "Fix ellipsis display logic in pagination template"
This reverts commit 2fa851e650.
2020-08-06 13:42:08 +02:00
Joe Mooring 2fa851e650 Fix ellipsis display logic in pagination template
Closes #7523
2020-07-31 16:08:23 +02:00
Joe Mooring a06c06a5c2 Fix date format in internal schema template
Prior to this change, the offset indicator for dates with positive
offsets was rendered as &#43; instead of +.

Fixes #7495
2020-07-23 15:57:20 +02:00
Bjørn Erik Pedersen eded9ac2a0 resources/js: Simplify options handling
Mostly to minify cache hash breakage.

Updates #7499
2020-07-22 10:13:30 +02:00
Bjørn Erik Pedersen c91dbe4ce9 Fix baseof block regression
From Hugo 0.74.0.

Fixes #7478
2020-07-13 20:45:09 +02:00
Bjørn Erik Pedersen 25e3da3343
docs: Regenerate docs helper 2020-07-13 11:01:38 +02:00
Bjørn Erik Pedersen 9df98ec49c Add proper Media Type handling in js.Build
See #732
2020-07-13 10:56:23 +02:00
Remko Tronçon 2fc3380707 Add js.Build asset bundling
Fixes #7321
2020-07-13 10:56:23 +02:00
Bjørn Erik Pedersen 12a65e76df Add openapi3.Unmarshal
Fixes #7442
Fixes #7443
2020-07-06 20:03:36 +02:00
Bjørn Erik Pedersen 42e150fbfa Fix server reload when non-HTML shortcode changes
Fixes #7448
2020-07-03 23:31:51 +02:00
Bjørn Erik Pedersen 028b356787
tpl/strings: Add strings.Count
Fixes #7453
2020-07-03 10:35:46 +02:00
Bjørn Erik Pedersen defd7106bf
tpl: Add debug.Dump
Fixes #3957
2020-07-02 09:04:46 +02:00
Bjørn Erik Pedersen 4a3efea7ef Add support for inline partials
Fixes #7444
2020-07-01 23:10:21 +02:00
Bjørn Erik Pedersen 01e249e97c
Regenerate templates 2020-06-12 11:29:04 +02:00
Joe Mooring 4b560cc119 Beautify HTML generated by pagination template
Fixes #7199.
2020-06-12 11:27:20 +02:00
Edouard 7eeebe1e5a
tpl/crypto: Add hmac 2020-06-05 20:04:11 +02:00
Sam Smith 3d9235e8fc tpl: Fix bad rounding in NumFmt
strconv.FormatFloat doesn't round properly sometimes, this adds a
different method of rounding, fixes #7116
2020-06-02 17:20:36 +02:00
Bjørn Erik Pedersen 6c3c6686f5 Fix Go template script escaping
Fixes #6695
2020-05-23 22:00:34 +02:00
Joe Mooring 991934497e Add math.Pow
Closes #7266
2020-05-14 10:00:31 +02:00
Daniel Tipping 6205d56b85 Use .Lastmod for og:updated_time
.Lastmod is the time at which the website was most recently updated,
rather than .Date which is the time at which the website content file
was created.
2020-05-07 18:42:20 +02:00
Tom 04b1a6d997
Add support for sort by boolean 2020-05-02 11:57:34 +02:00
Bjørn Erik Pedersen 6add6d77b4 Rename transpileJS to babel
And add a test.

Updates #5764
2020-04-29 10:51:33 +02:00
Niek de Wit 2a171ff1c5 resources: Add JavaScript transpiling solution
Add a new pipe called TranspileJS which uses the Babel cli. This makes it possible for users to write ES6 JavaScript code and transpile it to ES5 during website generation so that the code still works with older browser versions.

Fixes #5764
2020-04-29 10:51:33 +02:00
BurtonQin 5146dc614f tpl/tmplimpl/template: Change defer RLock to RUnlock 2020-04-21 13:23:31 +02:00
Elliott Sales de Andrade 7791a804e2
deps: Update to latest emoji package 2020-04-08 12:56:14 +02:00
Bjørn Erik Pedersen 2f721f8ec6
Add basic "post resource publish support"
Fixes #7146
2020-04-07 21:59:20 +02:00
Cameron Moore 8568928aa8 tpl: Extend Jsonify to support options map
Add support for prefix and indent options used by json.MarshalIndent
from the Go stdlib.
2020-04-07 20:01:57 +02:00
Cameron Moore 1bc93021e3 tpl: Extend Jsonify to support optional indent parameter
Fixes #5040
2020-04-07 20:01:57 +02:00
Bjørn Erik Pedersen 7204b354a9 Some minify configuration adjustments 2020-03-20 20:35:57 +01:00
SatowTakeshi 574c2959b8 Add minify config
Fixes #6750
Updates #6892
2020-03-20 20:35:57 +01:00
Bjørn Erik Pedersen ffcb4aeb8e Fix handling of HTML files without front matter
This means that any HTML file inside /content will be treated as a regular file.

If you want it processes with shortcodes and a layout, add front matter.

The defintion of an HTML file here is:

* File with extension .htm or .html
* With first non-whitespace character "<" that isn't a HTML comment.

This is in line with the documentation.

Fixes #7030
Fixes #7028
See #6789
2020-03-09 15:01:55 +01:00
satotake 8279d2e227
Support unComparable args of uniq/complement/in
Fixes #6105
2020-03-09 13:32:38 +01:00
Sam Smith c4fa2f0799 tpl: Fix error with unicode in file paths
Add url.QueryUnescape before reading file which allows files with
unicode in their paths to be read.

Fixes #6996
2020-03-09 13:31:04 +01:00
Carl Johnson ae383f04c8 {{ in }} should work with html.Template type
Fixes #7002
2020-03-03 13:37:42 +01:00
Sam Smith d7798906d8 tpl: Change error message on missing resource
Fixes #6942
2020-03-02 18:46:14 +01:00
Bjørn Erik Pedersen b0d850321e Fix rebuild logic when editing template using a base template
We have been doing too much work in that case.

Fixes #6968
2020-02-28 14:14:55 +01:00
Chris Dennis d184e5059c
tpl: Add math.Sqrt
Fixes #6941
2020-02-24 23:45:04 +01:00
Bjørn Erik Pedersen d73e37387c
tpl: Adjust the RSS taxonomy logic
See #6909
2020-02-18 17:29:46 +01:00
Bjørn Erik Pedersen aa3e183056
tpl: Fix RSS template for the terms listing
Fixes #6909
2020-02-18 16:55:30 +01:00
Bjørn Erik Pedersen eada236f87
Introduce a tree map for all content
This commit introduces a new data structure to store pages and their resources.

This data structure is backed by radix trees.

This simplies tree operations, makes all pages a bundle,  and paves the way for #6310.

It also solves a set of annoying issues (see list below).

Not a motivation behind this, but this commit also makes Hugo in general a little bit faster and more memory effective (see benchmarks). Especially for partial rebuilds on content edits, but also when taxonomies is in use.

```
name                                   old time/op    new time/op    delta
SiteNew/Bundle_with_image/Edit-16        1.32ms ± 8%    1.00ms ± 9%  -24.42%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file/Edit-16    1.28ms ± 0%    0.94ms ± 0%  -26.26%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories/Edit-16      33.9ms ± 2%    21.8ms ± 1%  -35.67%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs/Edit-16            40.6ms ± 1%    37.7ms ± 3%   -7.20%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree/Edit-16        56.7ms ± 0%    51.7ms ± 1%   -8.82%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates/Edit-16      19.9ms ± 2%    18.3ms ± 3%   -7.64%  (p=0.029 n=4+4)
SiteNew/Page_collections/Edit-16         37.9ms ± 4%    34.0ms ± 2%  -10.28%  (p=0.029 n=4+4)
SiteNew/Bundle_with_image-16             10.7ms ± 0%    10.6ms ± 0%   -1.15%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16         10.8ms ± 0%    10.7ms ± 0%   -1.05%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16           43.2ms ± 1%    39.6ms ± 1%   -8.35%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16                 47.6ms ± 1%    47.3ms ± 0%     ~     (p=0.057 n=4+4)
SiteNew/Deep_content_tree-16             73.0ms ± 1%    74.2ms ± 1%     ~     (p=0.114 n=4+4)
SiteNew/Many_HTML_templates-16           37.9ms ± 0%    38.1ms ± 1%     ~     (p=0.114 n=4+4)
SiteNew/Page_collections-16              53.6ms ± 1%    54.7ms ± 1%   +2.09%  (p=0.029 n=4+4)

name                                   old alloc/op   new alloc/op   delta
SiteNew/Bundle_with_image/Edit-16         486kB ± 0%     430kB ± 0%  -11.47%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file/Edit-16     265kB ± 0%     209kB ± 0%  -21.06%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories/Edit-16      13.6MB ± 0%     8.8MB ± 0%  -34.93%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs/Edit-16            66.5MB ± 0%    63.9MB ± 0%   -3.95%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree/Edit-16        28.8MB ± 0%    25.8MB ± 0%  -10.55%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates/Edit-16      6.16MB ± 0%    5.56MB ± 0%   -9.86%  (p=0.029 n=4+4)
SiteNew/Page_collections/Edit-16         16.9MB ± 0%    16.0MB ± 0%   -5.19%  (p=0.029 n=4+4)
SiteNew/Bundle_with_image-16             2.28MB ± 0%    2.29MB ± 0%   +0.35%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16         2.07MB ± 0%    2.07MB ± 0%     ~     (p=0.114 n=4+4)
SiteNew/Tags_and_categories-16           14.3MB ± 0%    13.2MB ± 0%   -7.30%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16                 69.1MB ± 0%    69.0MB ± 0%     ~     (p=0.343 n=4+4)
SiteNew/Deep_content_tree-16             31.3MB ± 0%    31.8MB ± 0%   +1.49%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16           10.8MB ± 0%    10.9MB ± 0%   +1.11%  (p=0.029 n=4+4)
SiteNew/Page_collections-16              21.4MB ± 0%    21.6MB ± 0%   +1.15%  (p=0.029 n=4+4)

name                                   old allocs/op  new allocs/op  delta
SiteNew/Bundle_with_image/Edit-16         4.74k ± 0%     3.86k ± 0%  -18.57%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file/Edit-16     4.73k ± 0%     3.85k ± 0%  -18.58%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories/Edit-16        301k ± 0%      198k ± 0%  -34.14%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs/Edit-16              389k ± 0%      373k ± 0%   -4.07%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree/Edit-16          338k ± 0%      262k ± 0%  -22.63%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates/Edit-16        102k ± 0%       88k ± 0%  -13.81%  (p=0.029 n=4+4)
SiteNew/Page_collections/Edit-16           176k ± 0%      152k ± 0%  -13.32%  (p=0.029 n=4+4)
SiteNew/Bundle_with_image-16              26.8k ± 0%     26.8k ± 0%   +0.05%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16          26.8k ± 0%     26.8k ± 0%   +0.05%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16             273k ± 0%      245k ± 0%  -10.36%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16                   396k ± 0%      398k ± 0%   +0.39%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16               317k ± 0%      325k ± 0%   +2.53%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16             146k ± 0%      147k ± 0%   +0.98%  (p=0.029 n=4+4)
SiteNew/Page_collections-16                210k ± 0%      215k ± 0%   +2.44%  (p=0.029 n=4+4)
```

Fixes #6312
Fixes #6087
Fixes #6738
Fixes #6412
Fixes #6743
Fixes #6875
Fixes #6034
Fixes #6902
Fixes #6173
Fixes #6590
2020-02-18 09:49:42 +01:00
Bjørn Erik Pedersen f45cb31728 Fix base template handling with preceding comments
Fixes #6816
2020-01-30 23:44:42 +01:00
Bjørn Erik Pedersen f441f67512 Fix baseof with regular define regression
Fixes #6790
2020-01-23 19:54:06 +01:00
Bjørn Erik Pedersen 2fefc01606
tpl/compare: Fix eq when > 2 args
Fixes #6786
2020-01-23 10:48:28 +01:00
Tan Yuanhong 0c251be66b Allow multiple arguments in ne/ge/gt/le/lt functions
Treat op arg1 arg2 arg3 ... as (arg1 op arg2) && (arg1 op arg3)
and so on for ne/ge/gt/le/lt.

Closes #6619
2020-01-23 10:36:35 +01:00
Bjørn Erik Pedersen c6d650c8c8
tpl/tplimpl: Rework template management to get rid of concurrency issues
This more or less completes the simplification of the template handling code in Hugo started in v0.62.

The main motivation was to fix a long lasting issue about a crash in HTML content files  without front matter.

But this commit also comes with a big functional improvement.

As we now have moved the base template evaluation to the build stage we now use the same lookup rules for `baseof` as for `list` etc. type of templates.

This means that in this simple example you can have a `baseof` template for the `blog` section without having to duplicate the others:

```
layouts
├── _default
│   ├── baseof.html
│   ├── list.html
│   └── single.html
└── blog
    └── baseof.html
```

Also, when simplifying code, you often get rid of some double work, as shown in the "site building" benchmarks below.

These benchmarks looks suspiciously good, but I have repeated the below with ca. the same result. Compared to master:

```
name                              old time/op    new time/op    delta
SiteNew/Bundle_with_image-16        13.1ms ± 1%    10.5ms ± 1%  -19.34%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16    13.0ms ± 0%    10.7ms ± 1%  -18.05%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16      46.4ms ± 2%    43.1ms ± 1%   -7.15%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16            52.2ms ± 2%    47.8ms ± 1%   -8.30%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16        77.9ms ± 1%    70.9ms ± 1%   -9.01%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16      43.0ms ± 0%    37.2ms ± 1%  -13.54%  (p=0.029 n=4+4)
SiteNew/Page_collections-16         58.2ms ± 1%    52.4ms ± 1%   -9.95%  (p=0.029 n=4+4)

name                              old alloc/op   new alloc/op   delta
SiteNew/Bundle_with_image-16        3.81MB ± 0%    2.22MB ± 0%  -41.70%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16    3.60MB ± 0%    2.01MB ± 0%  -44.20%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16      19.3MB ± 1%    14.1MB ± 0%  -26.91%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16            70.7MB ± 0%    69.0MB ± 0%   -2.40%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16        37.1MB ± 0%    31.2MB ± 0%  -15.94%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16      17.6MB ± 0%    10.6MB ± 0%  -39.92%  (p=0.029 n=4+4)
SiteNew/Page_collections-16         25.9MB ± 0%    21.2MB ± 0%  -17.99%  (p=0.029 n=4+4)

name                              old allocs/op  new allocs/op  delta
SiteNew/Bundle_with_image-16         52.3k ± 0%     26.1k ± 0%  -50.18%  (p=0.029 n=4+4)
SiteNew/Bundle_with_JSON_file-16     52.3k ± 0%     26.1k ± 0%  -50.16%  (p=0.029 n=4+4)
SiteNew/Tags_and_categories-16        336k ± 1%      269k ± 0%  -19.90%  (p=0.029 n=4+4)
SiteNew/Canonify_URLs-16              422k ± 0%      395k ± 0%   -6.43%  (p=0.029 n=4+4)
SiteNew/Deep_content_tree-16          401k ± 0%      313k ± 0%  -21.79%  (p=0.029 n=4+4)
SiteNew/Many_HTML_templates-16        247k ± 0%      143k ± 0%  -42.17%  (p=0.029 n=4+4)
SiteNew/Page_collections-16           282k ± 0%      207k ± 0%  -26.55%  (p=0.029 n=4+4)
```

Fixes #6716
Fixes #6760
Fixes #6768
Fixes #6778
2020-01-22 09:39:49 +01:00
Bjørn Erik Pedersen 1cf235412f
tpl: Put Go's internal template funcs in Hugo's map
```
name                            old time/op    new time/op    delta
SiteNew/Many_HTML_templates-16    43.4ms ± 0%    42.7ms ± 0%  -1.71%  (p=0.016 n=4+5)

name                            old alloc/op   new alloc/op   delta
SiteNew/Many_HTML_templates-16    17.5MB ± 0%    17.5MB ± 0%    ~     (p=0.690 n=5+5)

name                            old allocs/op  new allocs/op  delta
SiteNew/Many_HTML_templates-16      247k ± 0%      247k ± 0%    ~     (p=0.310 n=5+5)
```

Fixes #6717
2020-01-07 13:18:19 +01:00
Bjørn Erik Pedersen a82d2700fc
markup/goldmark: Make auto IDs GitHub compatible
You can turn off this behaviour:

```toml
[markup]
  [markup.goldmark]
    [markup.goldmark.parser]
      autoHeadingIDAsciiOnly = true
```
Note that the `anchorize` now adapts its behaviour depending on the default Markdown handler.

Fixes #6616
2020-01-04 19:46:01 +01:00
Bjørn Erik Pedersen 50cc7fe545
tpl: Do not return any value in errorf
Fixes #6653
2019-12-21 10:26:14 +01:00
Bjørn Erik Pedersen 1773d71d5b tpl: Add a warnf template func
Fixes #6628
2019-12-21 10:23:00 +01:00
Bjørn Erik Pedersen ccb1bf1abb
tpl/collections: Some more params merge adjustments
* If the end result is maps.Params, we need to lower the keys
* Also make sure to handle nested maps of different type

Update #6633
2019-12-19 20:50:30 +01:00
Bjørn Erik Pedersen 1b785a7a6d
tpl/collections: Fix merge vs Params
Fixes #6633
2019-12-18 21:31:34 +01:00
Bjørn Erik Pedersen d20ca37005 tpl: Get rid of the custom template truth logic
Fixes #6615
2019-12-18 20:05:22 +01:00
Bjørn Erik Pedersen e625088ef5
Add render template hooks for links and images
This commit also

* revises the change detection for templates used by content files in server mode.
* Adds a Page.RenderString method

Fixes #6545
Fixes #4663
Closes #6043
2019-12-18 11:44:40 +01:00
Bjørn Erik Pedersen 92c7f7ab85
tpl: Add some comments 2019-12-12 11:44:36 +01:00
Bjørn Erik Pedersen a03c631c42
Rework template handling for function and map lookups
This is a big commit, but it deletes lots of code and simplifies a lot.

* Resolving the template funcs at execution time means we don't have to create template clones per site
* Having a custom map resolver means that we can remove the AST lower case transformation for the special lower case Params map

Not only is the above easier to reason about, it's also faster, especially if you have more than one language, as in the benchmark below:

```
name                          old time/op    new time/op    delta
SiteNew/Deep_content_tree-16    53.7ms ± 0%    48.1ms ± 2%  -10.38%  (p=0.029 n=4+4)

name                          old alloc/op   new alloc/op   delta
SiteNew/Deep_content_tree-16    41.0MB ± 0%    36.8MB ± 0%  -10.26%  (p=0.029 n=4+4)

name                          old allocs/op  new allocs/op  delta
SiteNew/Deep_content_tree-16      481k ± 0%      410k ± 0%  -14.66%  (p=0.029 n=4+4)
```

This should be even better if you also have lots of templates.

Closes #6594
2019-12-12 10:04:35 +01:00
Bjørn Erik Pedersen 167c01530b
Create lightweight forks of text/template and html/template
This commit also removes support for Ace and Amber templates.

Updates #6594
2019-12-12 09:59:34 +01:00