Commit graph

1050 commits

Author SHA1 Message Date
Joe Mooring
912c6576bb parser/metadecoders: Add CSV lazyQuotes option to transform.Unmarshal
If true, a quote may appear in an unquoted field and a non-doubled quote
may appear in a quoted field. It defaults to false.

Closes #11884
2024-01-16 09:26:44 +01:00
Joe Mooring
e40b9fbbcf tpl/math: Add math.Rand template function
Closes #11833
2023-12-29 19:37:27 +01:00
Bjørn Erik Pedersen
8adba648cc all: Remove unused code
Using x/tools/cmd/deadcode
2023-12-18 19:51:26 +01:00
Bjørn Erik Pedersen
9f978d387f
Pull in the latest code from Go's template packages (#11771)
Fixes #10707
Fixes #11507
2023-12-04 12:07:54 +01:00
Razon Yang
14d85ec136
tpl: Allow using page resources on the images page parameter for opengraph, schema and twitter_cards templates
The page images selection order as follows:

1. Page's images parameter, image resources are supported.
2. Page's image resources that naming in *feature*, *cover* or *thumbnail* pattern.
3. If no page images specified, then the first one of site's images will be used as the fallback, supports site resources.
2023-12-04 12:05:41 +01:00
Joe Mooring
d24da1712f tpl/fmt: Print suppression help with erroridf
Closes #11506
2023-12-04 11:39:27 +01:00
Joe Mooring
4583b41305 tpl/transform: Display Chroma highlighting errors
Closes #9642
2023-12-04 11:38:23 +01:00
Joe Mooring
b4c5df42ff tpl/transform: Add transform.XMLEscape template function
Fixes #3268
2023-11-27 10:52:33 +01:00
Joe Mooring
8d32ca223d tpl/tplimpl: Remove superfluous type attr on script elements
Closes #6379
2023-11-27 10:45:53 +01:00
Joe Mooring
0bde6931ac helpers: Fix TrimShortHTML used by markdownify and RenderString
Closes #11698
2023-11-16 18:21:01 +01:00
Joe Mooring
cb98e9061b tpl/tplimpl: Fix deprecation logic in embedded templates
Closes #11658
2023-11-01 17:42:45 +01:00
Bjørn Erik Pedersen
ab21433689 Fix deprecation printing on info level
Fixes #11638
2023-10-31 10:42:23 +01:00
Joe Mooring
23fcfb7f74
tpl/tplimpl: Fix deprecation logic in RSS template
Closes #11639
2023-10-31 08:34:30 +01:00
Joe Mooring
a349aafb7f tpl/urls: Return strings from URL functions
Closes #11511
2023-10-29 18:12:24 +01:00
Bjørn Erik Pedersen
e54139c85b tpl/collections: Make delimit return a string
Closes #10876
Closes #11502
2023-10-28 11:54:23 +02:00
Bjørn Erik Pedersen
71fd79a3f4 Revise the deprecation logging
This introduces a more automatic way of increasing the log levels for deprecation log statements based on the version it was deprecated.

The thresholds are a little arbitrary, but

* We log INFO for 6 releases
* We log WARN for another 6 releases
* THen ERROR (failing the build)

This should give theme authors plenty of time to catch up without having the log filled with warnings.
2023-10-26 20:41:19 +02:00
Bjørn Erik Pedersen
46bdc03885
tpl/debug: Add average and median to timer output 2023-10-21 15:41:21 +02:00
Bjørn Erik Pedersen
5160c7efa5 tpl/debug: Add debug.Timer
Closes #11580
2023-10-20 09:46:45 +02:00
Joe Mooring
2eca1b3cc1 hugolib: Deprecate .Site.DisqusShortname
Use .Site.Config.Services.Disqus.Shortname instead.
2023-10-18 17:35:54 +02:00
Lars Lehtonen
625162674d
tpl/tplimpl: Fix dropped error 2023-10-18 17:33:00 +02:00
Joe Mooring
a692278bc6 hugolib: Deprecate .Site.GoogleAnalytics
Use .Site.Config.Services.GoogleAnalytics.ID instead.
2023-10-17 20:06:42 +02:00
Joe Mooring
d4016dd5cd tpl/tplimpl: Deprecate .Site.Author usage in RSS template 2023-10-17 20:04:49 +02:00
Joe Mooring
4910312ee7 tpl/tplimpl: Deprecate .Site.Social usage with internal templates 2023-10-17 20:04:24 +02:00
Oleksandr Redko
274852bcf2 all: Format files with gofmt 2023-10-05 14:45:55 +02:00
Joe Mooring
46da0b7aaa tpl/lang: Formally deprecate lang.NumFmt
Use lang.FormatNumberCustom instead.
2023-09-27 17:34:45 +02:00
Joe Mooring
75f56b4ce6 tpl/collections: Fix and deprecate echoParams
Fixes #11498
2023-09-27 17:34:13 +02:00
Carl Johnson
c32094ace1 google_analytics_async.html: Add deprecation warning 2023-09-23 18:57:19 +02:00
Bjørn Erik Pedersen
1e9b87f760 Upgrade to Go 1.21.1
See https://github.com/golang/go/issues?q=milestone%3AGo1.21.1+label%3ACherryPickApproved

Fixes #11474
Fixes #11414
2023-09-21 21:38:41 +02:00
Bjørn Erik Pedersen
24b1be45c1 Go 1.21 Upgrade
Fixes #11351
2023-08-23 21:49:27 +02:00
Bjørn Erik Pedersen
ade7ec8187 Add Page.RenderShortcodes
A layouts/shortcodes/include.html shortcode may look like this:

```html
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
```

Fixes #7297
2023-08-03 20:00:57 +02:00
Bjørn Erik Pedersen
ef6e813ca8
tpl/collections: Add BenchmarkWhereOps
```
BenchmarkWhereOps/eq-10 	    8702	    120410 ns/op	   52280 B/op	    2515 allocs/op
BenchmarkWhereOps/ne-10 	    9829	    120759 ns/op	   52280 B/op	    2515 allocs/op
BenchmarkWhereOps/like-10           6754	    176377 ns/op	   52917 B/op	    2515 allocs/op
```
2023-07-28 10:08:13 +02:00
Joe Mooring
f4598a0986 tpl/collections: Add like operator to where function
Closes #11279
2023-07-28 09:53:00 +02:00
Joe Mooring
dc2a544fac tpl/collections: Fix description of apply function
The collections.Apply template function cannot be used with maps.
2023-07-28 09:51:01 +02:00
Bjørn Erik Pedersen
4d7af757c9
Add a common regexp cache
```
BenchmarkGetOrCompileRegexp-10    	73959368	        13.71 ns/op	       0 B/op	       0 allocs/op
BenchmarkCompileRegexp-10         	 3143529	       380.1 ns/op	     872 B/op	      10 allocs/op
```
2023-07-27 19:23:12 +02:00
Bjørn Erik Pedersen
5bec50838c tpl/collections: Fix WordCount (etc.) regression in Where, Sort, Delimit
Fixes #11234
2023-07-11 12:11:39 +02:00
Bjørn Erik Pedersen
a78b17d7f1 Make imageConfig work with modules
Fixes #11205
2023-07-08 17:20:18 +02:00
Bjørn Erik Pedersen
79639c981c Fix output formats and media type per language config regression
Fixes #11159
2023-06-28 12:33:33 +02:00
khayyam
b74b8d6478
common/collections: Fix append regression to allow appending nil
Closes #11180
2023-06-28 09:41:36 +02:00
Oleksandr Redko
e3308a0bbc tpl/tplimpl: Fix typo in global variable name 2023-06-26 15:12:21 +02:00
Bjørn Erik Pedersen
7c9fada778 Replace the old log setup, with structured logging etc.
Fixes #11124
2023-06-18 13:03:04 +02:00
Bjørn Erik Pedersen
ee359df172 Fix upstream Go templates bug with reversed key/value assignment
The template packages are based on go1.20.5 with the patch in befec5ddbbfbd81ec84e74e15a38044d67f8785b  added.

This also includes a security fix that now disallows Go template actions in JS literals (inside backticks).

This will throw an error saying "... appears in a JS template literal".

If you're really sure this isn't a security risk in your case, you can revert to the old behaviour:

```toml
[security]
[security.gotemplates]
allowActionJSTmpl = true
```

See https://github.com/golang/go/issues/59234

Fixes #11112
2023-06-15 23:04:33 +02:00
Bjørn Erik Pedersen
d178fe94fe tpl/collections: Fix append when appending a slice to a slice of slices
Fixes #11093
2023-06-14 20:18:54 +02:00
Bjørn Erik Pedersen
2ba2271e4a
tpl/math: Allow variadic math functions to take slice args, add math.Product, math.Sum
* Update math.Min and math.Max to allow 1 or more args, either scalar or slice, or combination of the two
* Add math.Sum (allow 1 or more args, either scalar or slice, or combination of the two)
* Add math.Product (allow 1 or more args, either scalar or slice, or combination of the two)

Fixes #11030
2023-06-13 20:00:00 +02:00
Oleksandr Redko
382c726e63 markup: Fix typo in function and struct names 2023-06-01 17:59:44 +02:00
Oleksandr Redko
4c46f9400b all: Replace deprecated ioutil with io and os 2023-06-01 17:52:21 +02:00
Joe Mooring
ff77a927f9 tpl/tplimpl: Use .Language.LanguageCode in built-in templates 2023-05-30 20:10:16 +02:00
Bjørn Erik Pedersen
32585696be Fix potential deadlock in ByParam
Fixes #11039
2023-05-29 14:01:07 +02:00
Bjørn Erik Pedersen
b6e6438f7f docs: Regen docshelper 2023-05-22 18:54:34 +02:00
InLaw
2db7ec622f
tpl/tplimpl: Add img loading attribute to figure shortcode (#10927) 2023-05-21 12:28:45 -07:00
Bjørn Erik Pedersen
7c7baa6183 Add hugo.WorkingDir
Fixes #10969
2023-05-20 17:45:56 +02:00
Joe Mooring
150d190ff0 tpl/urls: Return empty string when JoinPath has zero args 2023-05-20 11:14:18 +02:00
Bjørn Erik Pedersen
e4e0313c80
tpl/urls: Fix build broken by a merge 2023-05-19 10:57:03 +02:00
Joe Mooring
5b3e165bad tpl/urls: Add JoinPath template function
See https://pkg.go.dev/net/url#JoinPath

Closes #9694
2023-05-19 10:31:17 +02:00
Oleksandr Redko
610cedaa61 all: Fix comments for exported functions and packages 2023-05-18 21:25:27 +02:00
Joe Mooring
1155bbca9d tpl/lang: document delimiter option for FormatNumberCustom
Closes gohugoio/hugoDocs#1760
2023-05-17 23:35:43 +02:00
Oleksandr Redko
bda082c98c
tpl: Add math.Abs
Fixes #10941.
2023-05-16 18:32:07 +02:00
Bjørn Erik Pedersen
241b21b0fd Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code.

Also,

* Lower case the default output format names; this is in line with the custom ones (map keys) and how
it's treated all the places. This avoids doing `stringds.EqualFold` everywhere.

Closes #10896
Closes #10620
2023-05-16 18:01:29 +02:00
Joe Mooring
5c7b79cf7f tpl/strings: Clarify findRESubmatch description 2023-04-27 22:02:41 +02:00
Bjørn Erik Pedersen
f1062519ae
tpl/debug: Add VisualizeSpaces 2023-04-20 11:27:55 +02:00
Andreas Deininger
05c095a0e6 resources.functions: improve validation 2023-03-20 14:53:57 +01:00
septs
f5eddf89bf
tpl/math: Return error if less than 2 input numbers
Fixes #10827
2023-03-14 09:28:38 +01:00
Andreas Deininger
d55af2abf0 Run gofmt -s on source files 2023-03-12 10:32:29 +01:00
septs
84201e8d5d
tpl/math: Allow multi numbers in add, sub, mul, div, min and max 2023-03-11 11:21:08 +01:00
Jonathan Fisher
d171d1543d tpl: Add hasSuffix alias
strings.HasPrefix already has an alias of hasPrefix
but strings.HasSuffix has no such alias.
This PR adds a hasSuffix alias to the tpl function with corresponding
function documentation.
It also adds a Minor update to the hasPrefix function documentation
re: keywords and relatedfuncs.

 Completes https://github.com/gohugoio/hugo/issues/10474
2023-03-08 10:18:34 +01:00
Bjørn Erik Pedersen
df5608f8a0 Allow page.TableOfContents on self in shortcode
Fixes #10791
2023-03-05 12:51:57 +01:00
Bjørn Erik Pedersen
f56ce01ae1
tpl/partial: Consolidate GoDoc 2023-03-04 22:04:01 +01:00
Bjørn Erik Pedersen
3bbeb5688c Fix "context canceled" with partial
Make sure the context used for timeouts isn't created based on the incoming
context, as we have cases where this can cancel the context prematurely.

Fixes #10789
2023-03-04 21:29:05 +01:00
Bjørn Erik Pedersen
6c798eba60 Page context handling in i18n
This is a workaround. We need to improve on this, but not today.

Fixes #10782
2023-03-04 17:19:14 +01:00
Oleksandr Redko
36ce3a4a9d Correct typos in Go comments 2023-03-02 16:32:32 +01:00
Bjørn Erik Pedersen
eef23a7f27 Fix "page" not defined
Fixes #10774
2023-03-02 10:39:44 +01:00
Joe Mooring
66f94b4945 tpl/tplimpl: Remove the Google News internal template
This was deprecated, with a warning message, on 21 Nov 2021.

Reference #9190
2023-03-01 18:11:44 +01:00
Khayyam Saleem
c0d15a2897
strings: fix Truncate behavior for formatted html
Before this fix, strings.Truncate would erroneously re-include
attributes from the opening tag in the closing tag when closing
formatted html, due to a bug in how tagnames were extracted from the
regex capture group for html tags used in `truncate.go`. This change
ensures that only the tagname is retained and all attributes are discarded
when storing the tags for closing them later.

Fixes #10399
2023-03-01 17:59:50 +01:00
Bjørn Erik Pedersen
2a61910e82
tpl/strings: Adjust benchmark 2023-03-01 17:59:02 +01:00
Bjørn Erik Pedersen
079d1b6540
tpl/strings: Add BenchmarkTruncate 2023-03-01 17:51:09 +01:00
Oleksandr Redko
d453c12742 Replace deprecated ioutil with io and os
https://pkg.go.dev/io/ioutil is deprecated since Go 1.16.
2023-03-01 16:28:43 +01:00
Bjørn Erik Pedersen
ce524d0b5e Add a page template func
Fixes #9339
2023-02-25 19:53:18 +01:00
Bjørn Erik Pedersen
ecf3cd514f tocss: Simplify the hugo:vars type handling
Instead of maintaing a list of all CSS units and functions this commit:

* Uses 3 regexps to detect typed CSS values (e.g. `24px`) + properly handle numeric Go types.
* These regexps may have some false positives -- e.g. strings that needs to be quoted.
* For that rare case, you can mark the string with e.g. `"32xxx" | css.Quoted`
* For the opposite case:  `"32" | css.Unquoted`

Updates #10632
2023-02-22 13:26:10 +01:00
Bjørn Erik Pedersen
094135ff96 tpl/internal: Sync Go template src to Go 1.20
Updates #10691
2023-02-22 11:26:52 +01:00
Bjørn Erik Pedersen
90da7664bf Add page fragments support to Related
The main topic of this commit is that you can now index fragments (content heading identifiers) when calling `.Related`.

You can do this by:

* Configure one or more indices with type `fragments`
* The name of those index configurations maps to an (optional) front matter slice with fragment references. This allows you to link
page<->fragment and page<->page.
* This also will index all the fragments (heading identifiers) of the pages.

It's also possible to use type `fragments` indices in shortcode, e.g.:

```
{{ $related := site.RegularPages.Related .Page }}
```

But, and this is important, you need to include the shortcode using the `{{<` delimiter. Not doing so will create infinite loops and timeouts.

This commit also:

* Adds two new methods to Page: Fragments (can also be used to build ToC) and HeadingsFiltered (this is only used in Related Content with
index type `fragments` and `enableFilter` set to true.
* Consolidates all `.Related*` methods into one, which takes either a `Page` or an options map as its only argument.
* Add `context.Context` to all of the content related Page API. Turns out it wasn't strictly needed for this particular feature, but it will
soon become usefil, e.g. in #9339.

Closes #10711
Updates #9339
Updates #10725
2023-02-21 17:56:41 +01:00
Bjørn Erik Pedersen
9af78d1100
tpl/collections: Improve error message in Index 2023-02-08 10:22:20 +01:00
Bjørn Erik Pedersen
fce0890484 tpl/strings: Add strings.ContainsNonSpace 2023-02-05 20:08:44 +01:00
Joe Mooring
4ccc8cfb4c Fix description of collections.Uniq 2023-01-31 08:12:45 +01:00
Bjørn Erik Pedersen
4ef9baf5bd Only invoke a given cached partial once
Note that this is backed by a LRU cache (which we soon shall see more usage of), so if you're a heavy user of cached partials it may be evicted and
refreshed if needed. But in most cases every partial is only invoked once.

This commit also adds a timeout (the global `timeout` config option) to make infinite recursion in partials
easier to reason about.

```
name              old time/op    new time/op    delta
IncludeCached-10    8.92ms ± 0%    8.48ms ± 1%   -4.87%  (p=0.016 n=4+5)

name              old alloc/op   new alloc/op   delta
IncludeCached-10    6.65MB ± 0%    5.17MB ± 0%  -22.32%  (p=0.002 n=6+6)

name              old allocs/op  new allocs/op  delta
IncludeCached-10      117k ± 0%       71k ± 0%  -39.44%  (p=0.002 n=6+6)
```

Closes #4086
Updates #9588
2023-01-25 17:35:23 +01:00
Bjørn Erik Pedersen
2fb40ece5d tpl/strings: Add findRESubmatch
Fixes #10594
2023-01-17 12:14:11 +01:00
Bjørn Erik Pedersen
e402d91ee1 Misc doc, code refactoring to improve documentation 2023-01-04 18:01:26 +01:00
Bjørn Erik Pedersen
3c51625c71 Make readFile return nil when file not found (note)
Fixes #9620
2023-01-04 18:01:26 +01:00
acclassic
f95fd57aac
tpl/compare: Sort special float values as string
When sorting strings a worng order is returned. This happens because the strings are first converted
to floating values to check whether or not they should be sorted as
floating values. When an error is returned the strings will be
handled as string literals.
No error will be returned when parsing Inf, Infinity or NaN (case insensitive) because they
will be coverted to special floating point values and therefore are
legal float values.
Now we check if the returned converted values are special floating
values and treat them as string literals.

Fixes #10389
2023-01-02 17:35:08 +01:00
Bjørn Erik Pedersen
e754d5cb3e
tpl/diagrams: Move Goat to its own file 2022-12-25 14:02:22 +01:00
Joe Mooring
4989da653d Revert "tpl/tplimpl: Use https in sitemap templates"
This reverts commit 3fd0b78498.
2022-12-22 08:53:58 +01:00
Bjørn Erik Pedersen
cd1ed563a8 tpl: Improve template funcs GoDoc 2022-12-21 15:33:02 +01:00
Bjørn Erik Pedersen
aa2c724195 tpl/resources: Fix data race in ToCSS
Fixes #10542
2022-12-21 12:26:42 +01:00
Bjørn Erik Pedersen
ad2059878a Also consider wrapped errors when checking for file IsNotExist errors
Fixes #10534
2022-12-14 13:51:06 +01:00
Bjørn Erik Pedersen
87e898a17a tpl/openapi3: Wrap *kopenapi3.T
To make it easier to document.
2022-12-14 12:29:40 +01:00
Joe Mooring
3fd0b78498 tpl/tplimpl: Use https in sitemap templates
Closes #10515
2022-12-11 18:53:30 +01:00
Razon Yang
b82b547acb
tpl/embedded: Make Open Graph's series optional 2022-12-06 10:48:34 +01:00
Joe Mooring
0b976d2b40 tpl/tplimpl: Allow alternate comment syntax
Allow alternate comment syntax before block definitions:

{{/* foo */}}
{{- /* foo */}}
{{- /* foo */ -}}

Fixes #10495
2022-12-04 09:25:51 +01:00
Bjørn Erik Pedersen
d373774cbe tpl/collections: Fix some index cases where the indices given is a slice and be more lenient with nil inputs
See adjusted tests for detail.

Fixes #10489
2022-12-03 11:54:33 +01:00
Bjørn Erik Pedersen
7d5e3ab8a8 tpl: Misco GoDoc improvements 2022-12-03 11:54:33 +01:00
Joe Mooring
b8d5c378ba tpl: Use consistent delimiter spacing in examples 2022-11-25 09:54:35 +01:00
Bjørn Erik Pedersen
7855b47f07 Add a cache for lexers.Get
```
name                            old time/op    new time/op    delta
Codeblocks/Default-10              152ms ±11%      12ms ± 1%  -92.44%  (p=0.029 n=4+4)
Codeblocks/Hook_no_higlight-10     142ms ± 0%       7ms ± 0%  -95.36%  (p=0.029 n=4+4)

name                            old alloc/op   new alloc/op   delta
Codeblocks/Default-10             11.9MB ± 0%    11.7MB ± 0%   -1.59%  (p=0.029 n=4+4)
Codeblocks/Hook_no_higlight-10    4.62MB ± 1%    4.43MB ± 0%   -4.08%  (p=0.029 n=4+4)

name                            old allocs/op  new allocs/op  delta
Codeblocks/Default-10               209k ± 0%      209k ± 0%   -0.03%  (p=0.029 n=4+4)
Codeblocks/Hook_no_higlight-10     68.4k ± 0%     68.3k ± 0%   -0.06%  (p=0.029 n=4+4)

```
2022-11-24 13:18:33 +01:00