Bjørn Erik Pedersen
d1c394442b
tpl: Fix codeblock hook resolve issue
...
Fixes #13593
2025-04-11 18:59:42 +02:00
Bjørn Erik Pedersen
1074e01152
tpl: Fix legacy section mappings
...
Fixes #13584
2025-04-11 18:23:51 +02:00
Bjørn Erik Pedersen
c19f1f2363
tpl: Resolve layouts/all.html for all html output formats
...
Fixes #13587
2025-04-11 18:23:51 +02:00
Bjørn Erik Pedersen
9221cbca49
tpl: Fix some baseof lookup issues
...
We were mistakingly using the templates (e.g. list.html) descriptor to resolve the base template and not the page,
which worked fine in most cases, but not all.
Fixes #13583
2025-04-11 18:23:51 +02:00
Bjørn Erik Pedersen
3b9f2a7ded
tpl: Skip dot and temp files inside /layouts
...
Fixes #13579
2025-04-10 18:41:01 +02:00
Bjørn Erik Pedersen
383dd82f95
tpl: Warn and skip non-hook templates inside /layouts/_markup
...
Fixes #13577
2025-04-10 16:54:05 +02:00
Bjørn Erik Pedersen
208a0de6c3
tpl: Add a partial lookup cache
...
````
│ stash.bench │ perf-v146.bench │
│ sec/op │ sec/op vs base │
LookupPartial-10 248.00n ± 0% 14.75n ± 2% -94.05% (p=0.002 n=6)
│ stash.bench │ perf-v146.bench │
│ B/op │ B/op vs base │
LookupPartial-10 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.002 n=6)
│ stash.bench │ perf-v146.bench │
│ allocs/op │ allocs/op vs base │
LookupPartial-10 3.000 ± 0% 0.000 ± 0% -100.00% (p=0.002 n=6)
```
THe speedup above assumes reuse of the same partials over and over again, which I think is not uncommon.
This commits also adds some more lookup benchmarks. The current output of these on my MacBook looks decent:
```
BenchmarkLookupPagesLayout/Single_root-10 3031562 395.5 ns/op 0 B/op 0 allocs/op
BenchmarkLookupPagesLayout/Single_sub_folder-10 2515915 480.9 ns/op 0 B/op 0 allocs/op
BenchmarkLookupPartial-10 84808112 14.13 ns/op 0 B/op 0 allocs/op
BenchmarkLookupShortcode/toplevelpage-10 8111779 148.2 ns/op 0 B/op 0 allocs/op
BenchmarkLookupShortcode/nestedpage-10 8088183 148.6 ns/op 0 B/op 0 allocs/op
```
Note that in the above the partial lookups are cahced, the others not (they are harder to cache because of the page path).
Closes #13571
2025-04-10 11:07:19 +02:00
Bjørn Erik Pedersen
d4c6dd16b1
tpl: Add templates.Current
...
This commit also
* Unexport all internal state in TemplateInfo.
* Make the dispatcher keys used for passing context.Context into uint8 from string to save memory allocations.
Co-authored-by: Joe Mooring <joe@mooring.com >
Updates #13571
2025-04-09 20:15:40 +02:00
Joe Mooring
1e00842489
tpl/tplimpl: Update embedded pagination template
2025-04-07 21:29:53 +02:00
Bjørn Erik Pedersen
83cfdd78ca
Reimplement and simplify Hugo's template system
...
See #13541 for details.
Fixes #13545
Fixes #13515
Closes #7964
Closes #13365
Closes #12988
Closes #4891
2025-04-06 20:59:41 +02:00
Joe Mooring
07cbe5701e
tpl/time: Add time.In function
...
Closes #13548
2025-04-03 09:45:51 +02:00
Joe Mooring
6f14dbe24c
tpl/tplimpl: Fix full screen option in vimeo and youtube shortcodes
...
Closes #13531
Co-authored-by: Stefan Ritter <60473875+gideonstar-git@users.noreply.github.com >
2025-03-27 12:32:00 +01:00
Joe Mooring
b9add1c702
tpl/tplimpl: Add loading attribute to Vimeo shortcode
...
Closes #13445
2025-03-11 21:02:12 +01:00
Will Faught
eebea9ec41
tpl: Add trailing newline to robots.txt template
2025-03-05 15:02:50 +01:00
Bjørn Erik Pedersen
521911a576
all: Run modernize -fix ./...
2025-02-26 11:44:25 +01:00
Christian Oliff
2f4e666d7e
tpl: HTTPS the instagram Shortcode JS
...
This JavaScript will always load over HTTPS so it's best to specify that. Protocol-less loaded resources are an anti-pattern (REF: https://www.paulirish.com/2010/the-protocol-relative-url/ )
2025-02-26 09:27:31 +01:00
Bjørn Erik Pedersen
04f21b4d80
Add transform.PortableText
...
Using this in a content adapter could look like this:
```handlebars
{{ $projectID := "<myproject>" }}
{{ $useCached := true }}
{{ $api := "api" }}
{{ if $useCached }}
{{/* See https://www.sanity.io/docs/api-cdn */}}
{{ $api = "apicdn" }}
{{ end }}
{{ $url := printf "https://%s.%s.sanity.io/v2021-06-07/data/query/production " $projectID $api }}
{{/* prettier-ignore-start */ -}}
{{ $q := `*[_type == 'post']{
title, publishedAt, summary, slug, body[]{
...,
_type == "image" => {
...,
asset->{
_id,
path,
url,
altText,
title,
description,
metadata {
dimensions {
aspectRatio,
width,
height
}
}
}
}
},
}`
}}
{{/* prettier-ignore-end */ -}}
{{ $body := dict "query" $q | jsonify }}
{{ $opts := dict "method" "post" "body" $body }}
{{ $t := debug.Timer "sanity.get" }}
{{ $r := resources.GetRemote $url $opts }}
{{ $t.Stop }}
{{ $m := $r | transform.Unmarshal }}
{{ $result := $m.result }}
{{ $t := debug.Timer "sanity.parse" }}
{{ range $result }}
{{ if not .slug }}
{{ continue }}
{{ end }}
{{ $markdown := transform.PortableText .body }}
{{ $t.Stop }}
{{ $content := dict
"mediaType" "text/markdown"
"value" $markdown
}}
{{ $params := dict
"portabletext" (.body | jsonify (dict "indent" " "))
}}
{{ $page := dict
"content" $content
"kind" "page"
"path" .slug.current
"title" .title
"date" (.publishedAt | time )
"summary" .summary
"params" $params
}}
{{ $.AddPage $page }}
{{ end }}
```
2025-02-25 19:35:47 +01:00
Bjørn Erik Pedersen
641403f7de
Fix Position for passthrough hooks
...
Fixes #13406
2025-02-17 12:23:49 +01:00
Bjørn Erik Pedersen
fd8b0fbf8a
Upgrade to Go 1.24
...
Fixes #13381
2025-02-12 22:01:25 +01:00
Bjørn Erik Pedersen
9b5f786df8
Deprecate kind, lang, and path from front matter
...
These were added to the page meta object when we implemented "pages from data", but were not meant to be used in front matter.
That is not supported, so we might as well add validation.
Fixes #12484
2025-02-10 21:22:43 +01:00
Bjørn Erik Pedersen
c2fb221209
Add ContentTypes to config
...
This is an empty struct for now, but we will most likely expand on that.
```
[contentTypes]
[contentTypes.'text/markdown']
```
The above means that only Markdown will be considered a content type. E.g. HTML will be treated as plain text.
Fixes #12274
2025-02-08 10:31:15 +01:00
Joe Mooring
7104de83ce
common/hugo: Adjust deprecation timing and message
...
Closes #13333
2025-02-03 18:32:30 +01:00
Alex Shpak
13b208e2f7
tpl/tplimpl: Remove leading whitespaces produced by Youtube shortcode
2025-01-31 09:29:10 +01:00
Joe Mooring
873a5cda1a
tpl/tplimpl: Improve shortcode test coverage
2025-01-24 09:10:45 +01:00
Joe Mooring
f42a4b6af5
tpl/tplimpl: Deprecate gist shortcode
...
Closes #13211
2025-01-23 20:12:36 +01:00
Bjørn Erik Pedersen
51bb2fedab
tpl/tplimpl: Skip TestTemplateFuncsExamples on s390x
...
Closes #13204
2025-01-23 10:18:43 +01:00
Joe Mooring
77a8e347bc
tpl/tplimpl: Deprecate comment shortcode
2025-01-22 19:38:02 +01:00
Joe Mooring
8de4ffb294
tpl/tplimpl: Fix context in shortcode error messages
...
Fixes #13279
2025-01-20 16:17:55 +01:00
Bjørn Erik Pedersen
1f5a15aba0
resources: Fix 2 image file cache key issues
...
* Always include the content hash in the cache key for unprocessed images.
* Always include the image config hash in the cache key.
This is also a major cleanup/simplification of the implementation in this area.
Note that this, unfortunately, forces new hashes/filenames for generated images.
Fixes #13273
Fixes #13272
2025-01-18 12:23:18 +01:00
Nicolas Friedli
8897113666
tpl: Add loading attribute to qr shortcode
2025-01-17 19:06:54 +01:00
Bjørn Erik Pedersen
1fad3832a9
tpl/tplimpl: Simplify some test assertions
2025-01-16 11:29:24 +01:00
Joe Mooring
1191467c05
tpl/tplimpl: Deprecate twitter shortcode in favor of x shortcode
...
Closes #13214
2025-01-16 10:33:34 +01:00
Bjørn Erik Pedersen
de7137cc35
tpl/collections: Use MapRange/SetIterKey/SetIterValue for Where, Sort and Merge
...
Some relevant benchmarks:
Where with maps:
```
cpu: Apple M1 Pro
│ master.bench │ fix-mapkeys.bench │
│ sec/op │ sec/op vs base │
WhereMap-10 79.26µ ± 1% 26.58µ ± 1% -66.46% (p=0.002 n=6)
│ master.bench │ fix-mapkeys.bench │
│ B/op │ B/op vs base │
WhereMap-10 56685.0 ± 0% 111.0 ± 1% -99.80% (p=0.002 n=6)
│ master.bench │ fix-mapkeys.bench │
│ allocs/op │ allocs/op vs base │
WhereMap-10 2003.000 ± 0% 4.000 ± 0% -99.80% (p=0.002 n=6)
```
Merge:
```
│ master.bench │ fix-mapkeys.bench │
│ sec/op │ sec/op vs base │
Merge-10 3.285µ ± 0% 2.268µ ± 1% -30.96% (p=0.002 n=6)
│ master.bench │ fix-mapkeys.bench │
│ B/op │ B/op vs base │
Merge-10 3.079Ki ± 0% 1.891Ki ± 0% -38.58% (p=0.002 n=6)
│ master.bench │ fix-mapkeys.bench │
│ allocs/op │ allocs/op vs base │
Merge-10 64.00 ± 0% 26.00 ± 0% -59.38% (p=0.002 n=6)
```
Sort:
```
cpu: Apple M1 Pro
│ master.bench │ fix-mapkeys.bench │
│ sec/op │ sec/op vs base │
SortMap-10 1008.0n ± 1% 915.5n ± 0% -9.18% (p=0.002 n=6)
│ master.bench │ fix-mapkeys.bench │
│ B/op │ B/op vs base │
SortMap-10 640.0 ± 0% 512.0 ± 0% -20.00% (p=0.002 n=6)
│ master.bench │ fix-mapkeys.bench │
│ allocs/op │ allocs/op vs base │
SortMap-10 16.00 ± 0% 15.00 ± 0% -6.25% (p=0.002 n=6)
```
2025-01-13 16:24:48 +02:00
Bjørn Erik Pedersen
956f915f77
tpl/collections: Add BenchmarkWhereMap
2025-01-13 12:57:48 +02:00
Bjørn Erik Pedersen
a2a4166f6d
tpl/collections: Add BenchmarkSortMap
2025-01-13 10:38:12 +02:00
Bjørn Erik Pedersen
39f582f9f4
tpl/collections: Add Merge benchmark
2025-01-13 10:32:41 +02:00
Bjørn Erik Pedersen
2501de7aab
resources/images: Refactor golden image tests to locate them closer to the implementation
2025-01-11 18:27:53 +02:00
Joe Mooring
8af04745fb
tpl/tplimpl: Use plain text for image render hook alt attribute
...
Co-authored-by: Heracles <email@heracl.es >
2025-01-10 19:44:39 +02:00
Bjørn Erik Pedersen
dde9d9d544
Adjust error handling in ToMath vs try (note)
...
Closes #13239
2025-01-09 11:47:19 +01:00
Bjørn Erik Pedersen
61d3d20129
templates: Fix handling of multiple defers in the same template
...
Fixes #13236
2025-01-09 07:59:25 +01:00
Joe Mooring
b13d0a68e6
tpl/images: Change signature of images.QR to images.QR TEXT OPTIONS
...
Closes #13230
2025-01-08 19:59:39 +01:00
Bjørn Erik Pedersen
5f2adad2c7
tpl/images: Format the QR hashes as hex
...
Slightly shorter, and it looks more like a ... hash.
2025-01-06 15:05:03 +01:00
Bjørn Erik Pedersen
0918e087ec
resources: Replace error handling in GetRemote with try (note)
...
Closes #13216
2025-01-06 12:22:17 +01:00
Joe Mooring
4ea94c451d
tpl/images: Add images.QR function
...
Closes #13205
2025-01-06 12:05:59 +01:00
Bjørn Erik Pedersen
5d2cbee989
Add try
...
Updates #9737
2025-01-05 15:32:21 +01:00
Bjørn Erik Pedersen
4a5e94087b
Fix union, complement, symdiff, and intersect for transient resources
...
Fixes #13181
2024-12-22 19:25:03 +01:00
Bjørn Erik Pedersen
a5e5be234c
Fix panic on server rebuilds when using both base templates and template.Defer
...
Fixes #12963
2024-12-16 18:03:04 +01:00
Bjørn Erik Pedersen
565c30eac9
js: Fix js.Batch for multihost setups
...
Note that this is an unreleased feature.
Fixes #13151
2024-12-16 11:52:18 +01:00
Joe Mooring
a32c889a7b
tpl/tplimpl: Fix title attribute in details shortcode
2024-12-13 10:50:17 -08:00
Joe Mooring
852d868549
tpl/tplimpl: Update youtube shortcode
...
Pass a map instead of a slice to the collections.Querify function.
2024-12-13 15:16:55 +01:00