Skip to content

Commit e12cdbc

Browse files
authored
feat: add the cache_site_param_key to cache partial against site parameter (#53)
Support nested parameters, separated by dot, such as `foo.bar.fizz`
1 parent d6c3734 commit e12cdbc

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

layouts/partials/hugopress/functions/render-hooks.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
{{- partialCached .partial $ctx (index (apply (slice 0) .cache_key) 0) }}
2020
{{- else if ne .cache_param_key nil }}
2121
{{- partialCached .partial $ctx (index $page.Params .cache_param_key) }}
22+
{{- else if ne .cache_site_param_key nil }}
23+
{{- partialCached .partial $ctx (index site.Params .cache_site_param_key) }}
2224
{{- else }}
2325
{{- partialCached .partial $ctx }}
2426
{{- end }}

layouts/partials/hugopress/functions/settings.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
"module" $moduleName
2727
"partial" $partial)
2828
}}
29+
{{/* Transform cache keys only once. */}}
30+
{{- range slice "cache_param_key" "cache_site_param_key" }}
31+
{{- $cacheKey := . }}
32+
{{- with index $option $cacheKey }}
33+
{{- $option = merge $option (dict $cacheKey (split . ".")) }}
34+
{{- end }}
35+
{{- end }}
2936
{{- $hooks.Add $name (slice $option) }}
3037
{{- end }}
3138
{{- end }}

0 commit comments

Comments
 (0)