Commit graph

1089 commits

Author SHA1 Message Date
Patrice Chalin
039845804f
tpl/tplimpl: Trim descriptions rather than just chomp 2024-10-12 22:41:42 +02:00
Joe Mooring
1158e63072 markup/goldmark: Change default cell alignment in table render hook
Change the default table cell alignment from "left" to an empty string.

Closes #12886
2024-09-30 08:44:14 +02:00
Joe Mooring
d1ba52f3c3 tests: Address deprecation warnings and errors 2024-09-29 10:49:26 +02:00
Joe Mooring
0ea796dad1 tpl/compare: Use any data type for compare.Conditional condition
Improves #5792
2024-09-22 16:53:11 +02:00
Bjørn Erik Pedersen
e07028cb90 tpl: Remove RSS deprecation site.Author check
The check itself creates a warning which I guess was not intended.

We could possibly make that work, but it has been deprecated since Hugo 0.98, so just remove the usage.
2024-09-19 13:39:40 +02:00
Bjørn Erik Pedersen
28f621d4a7 internal/warpc: Improve the JS plugin API
* Move the error handling into commons and make sure the error returned also returns message errors
* Make the protocol version an int so it can be more easily compared
2024-09-12 13:51:37 +02:00
Bjørn Erik Pedersen
6d97ee711e Make all renderhook Text methods return template.HTML 2024-08-31 21:05:58 +02:00
Bjørn Erik Pedersen
f738669a4d Add Markdown render hooks for tables
Fixes #9316
Fixes #12811
2024-08-31 17:21:31 +02:00
Andreas Deininger
8fb933550f Fix deprecation warning for resources.ToCSS 2024-08-30 22:26:29 +02:00
Joe Mooring
a3684c8361 tpl/resources: Improve resources.Concat error message
Closes #7428
2024-08-30 08:39:29 +02:00
Patrice Chalin
53a8de21b8
tpl: Trim whitespace from google_analytics.html 2024-08-29 21:32:46 +02:00
Bjørn Erik Pedersen
2168c5b125 Upgrade to Go 1.23
Fixes #12763
2024-08-15 10:18:19 +02:00
Bjørn Erik Pedersen
83235262d0 tpl/transform: Don't run ToMath tests in parallel
Closes #12765
2024-08-14 16:58:49 +02:00
Bjørn Erik Pedersen
e1e1baa1bd Improve Katex error handling and fix handling of large expressions
* Make throwOnError=true the new default
* Handle JS errors as part of the RPC request/response flow
* Return a new Result type with .Err on it

This enables constructs on the form:

```handlebars
{{ with transform.ToMath "c = \\foo{a^2 + b^2}" }}
	{{ with .Err }}
	 	{{ warnf "error: %s" . }}
	{{ else }}
		{{ . }}
	{{ end }}
{{ end }}
```

Note that the new `Result` type behaves like `template.HTML` (or a string if needed) when printed, but it will panic if in a error state.

Closes #12748
2024-08-12 13:50:18 +02:00
Bjørn Erik Pedersen
e42263529c
Add katex option ThrowOnError
As an internal option for now. Katex misbehaves in error situations without a value set.
2024-08-11 20:57:15 +02:00
Bjørn Erik Pedersen
891aa00fe1 Add some more KaTeX options
And fix the options handling.

Closes #12745
Fixes #12746
2024-08-11 19:03:27 +02:00
Bjørn Erik Pedersen
946e6af0bb tpl/transform: Make Plainify and ToMath return template.HTML
None of these are useful as plain strings in the templates, which forces the users to do `transform.Plainify "foo" | safeHTML`.

If people have trust issues with the output of these functions, they need to just stop using them.

Closes #8732
2024-08-11 15:16:16 +02:00
Bjørn Erik Pedersen
fbfccb394b Fix compare of uints and ints in eq, gt etc.
Fixes #12733
2024-08-10 14:00:21 +02:00
Bjørn Erik Pedersen
33c0938cd5 Add build time math rendering
While very useful on its own (and combined with the passthrough render hooks), this also serves as a proof of concept of using WASI (WebAssembly System Interface) modules in Hugo.

This will be marked _experimental_ in the documentation. Not because it will be removed or changed in a dramatic way, but we need to think a little more how to best set up/configure similar services, define where these WASM files gets stored, maybe we can allow user provided WASM files plugins via Hugo Modules mounts etc.

See these issues for more context:

* https://github.com/gohugoio/hugo/issues/12736
* https://github.com/gohugoio/hugo/issues/12737

See #11927
2024-08-09 17:18:37 +02:00
Bjørn Erik Pedersen
10891f305e tpl/cast: Improve float
Make it support the new upstream rational number type in Exif.

See #12718
2024-08-06 22:26:43 +02:00
Bjørn Erik Pedersen
c07e94fa6d
Skip TestEchoParam
Is deprecated, will be remvoved soon.
2024-08-06 19:13:35 +02:00
Bjørn Erik Pedersen
69455fa422
Fix deprecation errors 2024-08-05 19:23:53 +02:00
n1xx1
566fe7ba12
resources/page: Expand parmalinks tokens in url
This change allows to use permalink tokens in url front matter fields. This should be useful to target more specific pages instead of using a global permalink configuration. It's expected to be used with cascade.

Fixes #9714
2024-08-01 12:14:29 +02:00
Bjørn Erik Pedersen
92573012e8 Bump to go 1.21 in go.mod 2024-08-01 12:07:27 +02:00
Bjørn Erik Pedersen
071f8b4466 tpl: Sync Go template packages with the Go 1.22.5 source 2024-08-01 12:07:27 +02:00
Bjørn Erik Pedersen
216a69a1ef Shorten processed image filenames
Fixes #12688
Fixes #12656
2024-07-31 16:44:06 +02:00
Bjørn Erik Pedersen
e67886c038 Consolidate all hashing to the common/hashing package
And remove now unsued hashing funcs.
2024-07-31 16:44:06 +02:00
Bjørn Erik Pedersen
d5eda13cb2 Replace the MD5 hashing of images with xxHash
Note that we only use this for change detection.

The previous implementation invoked `MD5FromReaderFast` that created a MD5 has from 8 64 bytes chunks in the file, which is obviously very fast. The new implementation creates the hash from the entire file and ... seems to be even more effective:

```
name          old time/op    new time/op    delta
HashImage-10    9.45µs ±21%   10.89µs ± 1%     ~     (p=0.343 n=4+4)

name          old alloc/op   new alloc/op   delta
HashImage-10      144B ± 0%        8B ± 0%  -94.44%  (p=0.029 n=4+4)

name          old allocs/op  new allocs/op  delta
HashImage-10      4.00 ± 0%      1.00 ± 0%  -75.00%  (p=0.029 n=4+4)
```
2024-07-31 16:44:06 +02:00
Bjørn Erik Pedersen
78db8aebca identity: Upgrade to github.com/mitchellh/hashstructure/v2 v2.0.2
```
name                 old time/op    new time/op    delta
HashString/n28-10       131ns ± 7%     133ns ±19%   ~     (p=0.343 n=4+4)
HashString/n112-10      237ns ± 5%     241ns ± 3%   ~     (p=0.229 n=4+4)
HashString/n448-10      688ns ± 3%     687ns ± 1%   ~     (p=0.886 n=4+4)
HashString/n1792-10    2.51µs ± 3%    2.56µs ± 3%   ~     (p=0.200 n=4+4)
HashString/n7168-10    10.1µs ± 2%    10.0µs ± 4%   ~     (p=0.686 n=4+4)

name                 old alloc/op   new alloc/op   delta
HashString/n28-10       80.0B ± 0%     80.0B ± 0%   ~     (all equal)
HashString/n112-10       160B ± 0%      160B ± 0%   ~     (all equal)
HashString/n448-10       496B ± 0%      496B ± 0%   ~     (all equal)
HashString/n1792-10    1.84kB ± 0%    1.84kB ± 0%   ~     (all equal)
HashString/n7168-10    8.24kB ± 0%    8.24kB ± 0%   ~     (all equal)

name                 old allocs/op  new allocs/op  delta
HashString/n28-10        4.00 ± 0%      4.00 ± 0%   ~     (all equal)
HashString/n112-10       4.00 ± 0%      4.00 ± 0%   ~     (all equal)
HashString/n448-10       4.00 ± 0%      4.00 ± 0%   ~     (all equal)
HashString/n1792-10      4.00 ± 0%      4.00 ± 0%   ~     (all equal)
HashString/n7168-10      4.00 ± 0%      4.00 ± 0%   ~     (all equal)
```

Closes #11644
2024-07-31 16:44:06 +02:00
raoulb
9d2b5f98d0
math: Add trigonometric functions and some angle helper functions
This commit adds these new template functions in the `math` namespace:

math.Acos
math.Asin
math.Atan
math.Atan2
math.Cos
math.Pi
math.Sin
math.Tan
math.ToDegrees
math.ToRadians

Co-authored-by: Joe Mooring <joe@mooring.com>
2024-07-29 11:05:36 +02:00
Bjørn Erik Pedersen
4d8bfa7f1c
tpl: Use xxHash instead of MD5 to hash the deferred templates
Motivation is performance. These templates are typically very small, so the win is minor, I guess.
2024-07-17 12:51:49 +02:00
Bjørn Erik Pedersen
f0ed91caba Throw error if resources.PostProcess is used in a deferred template
That just doesn't work.

See #12655
2024-07-17 12:47:25 +02:00
Bjørn Erik Pedersen
644d55475d Add hash.XxHash
Also move the non crypto hash funcs into this new package.

This is much faster than e.g. MD5, especially for larger inputs:

```
BenchmarkXxHash/xxHash_43-10         	 9917955	       112.2 ns/op	      56 B/op	       4 allocs/op
BenchmarkXxHash/mdb5_43-10           	 6017239	       204.1 ns/op	      96 B/op	       3 allocs/op
BenchmarkXxHash/fnv32a_43-10         	14407333	        82.30 ns/op	      16 B/op	       1 allocs/op
BenchmarkXxHash/xxHash_4300-10       	 2916892	       409.7 ns/op	      56 B/op	       4 allocs/op
BenchmarkXxHash/mdb5_4300-10         	  159748	      7491 ns/op	    4912 B/op	       3 allocs/op
BenchmarkXxHash/fnv32a_4300-10       	  218210	      5510 ns/op	      16 B/op	       1 allocs/op
```

Fixes #12635
2024-07-06 14:08:15 +02:00
Bjørn Erik Pedersen
e1317dd322 Add css.TailwindCSS
Closes #12618
Closes #12620
2024-06-25 15:48:02 +02:00
Bjørn Erik Pedersen
eddcd2bac6 Clean up the css related template funcs package structure
Deprecate and move:

* resources.ToCSS => css.SASS
* resources.PostProcess => css.PostProcess
* resources.Babel => js.Babel

Updates #12618
2024-06-25 15:48:02 +02:00
Bjørn Erik Pedersen
c880faa998
tpl/debug: Fix reset of debug timers when running the server
Fixes #12621
2024-06-24 12:49:35 +02:00
Bjørn Erik Pedersen
6cd0784e44 Implement defer
Closes #8086
Closes #12589
2024-06-23 11:25:47 +02:00
Bjørn Erik Pedersen
8731d88222
Fix Erroridf/Warnidf mixed case issue
Fixes #12617
2024-06-22 19:01:56 +02:00
Bjørn Erik Pedersen
447108fed2
Add a HTTP cache for remote resources.
Fixes #12502
Closes #11891
2024-06-04 16:07:39 +02:00
Joe Mooring
b893a09aa6 tpl/tplimpl: Resolve render hook destinations with leading ./
Closes #12514
2024-05-21 09:38:25 +02:00
Joe Mooring
74ab839ccb tpl/tplimpl: Plainify title and description in twitter_cards.html
Closes #12433
Improves #10900
2024-05-14 14:45:04 +02:00
Joe Mooring
92290aa892 tpl/tplimpl: Plainify title and description in schema.html
Closes #12432
2024-05-14 14:18:49 +02:00
Bjørn Erik Pedersen
e2d66e3218
Create pages from _content.gotmpl
Closes #12427
Closes #12485
Closes #6310
Closes #5074
2024-05-14 13:12:08 +02:00
Joe Mooring
87ab7f7ffc tpl/tplimpl: Improve locale value in opengraph.html
Closes #12480
2024-05-14 10:24:17 +02:00
Joe Mooring
6dfeb9f038 tpl/tplimpl: Retain query string and fragment in render-image.html
Closes #12468
2024-05-10 22:32:48 +02:00
Bjørn Erik Pedersen
503d20954f
Make the cache eviction logic for stale entities more robust
Fixes #12458
2024-05-04 19:45:43 +02:00
Bjørn Erik Pedersen
7203a95a60 Fix rebuilds when running hugo -w
This was partly broken in Hugo 0.123.0.

We have two internal config options that gets set from the CLI:

* Running; a web server is running
* Watching; either set via `hugo -w`  or `hugo server --watch=false`

Part of the change detection code wrongly used the `Running` as a flag when `Watching` would be the correct.

Fixes #12296
2024-04-25 14:35:49 +02:00
Joe Mooring
fb51b698b3 tpl/tplimpl: Fix double-escaping in opengraph template
Closes #12418
2024-04-25 10:03:17 +02:00
Bjørn Erik Pedersen
15a4b9b337 tpl: Escape .Title in built-in image and link render hooks
Co-authored-by: Joe Mooring <joe@mooring.com>
2024-04-22 16:54:24 +02:00
Joe Mooring
10a8448eee tpl/tplimpl: Improve embedded templates
- Do not call the YouTube oEmbed API
- Do not include the Hugo version in RSS feeds

Closes #12396
2024-04-22 15:57:37 +02:00