Skip to content

Commit

Permalink
feat: add the cache_site_param_key to cache partial against site para…
Browse files Browse the repository at this point in the history
…meter (#53)

Support nested parameters, separated by dot, such as `foo.bar.fizz`
  • Loading branch information
razonyang authored Jun 1, 2024
1 parent d6c3734 commit e12cdbc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions layouts/partials/hugopress/functions/render-hooks.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
{{- partialCached .partial $ctx (index (apply (slice 0) .cache_key) 0) }}
{{- else if ne .cache_param_key nil }}
{{- partialCached .partial $ctx (index $page.Params .cache_param_key) }}
{{- else if ne .cache_site_param_key nil }}
{{- partialCached .partial $ctx (index site.Params .cache_site_param_key) }}
{{- else }}
{{- partialCached .partial $ctx }}
{{- end }}
Expand Down
7 changes: 7 additions & 0 deletions layouts/partials/hugopress/functions/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
"module" $moduleName
"partial" $partial)
}}
{{/* Transform cache keys only once. */}}
{{- range slice "cache_param_key" "cache_site_param_key" }}
{{- $cacheKey := . }}
{{- with index $option $cacheKey }}
{{- $option = merge $option (dict $cacheKey (split . ".")) }}
{{- end }}
{{- end }}
{{- $hooks.Add $name (slice $option) }}
{{- end }}
{{- end }}
Expand Down

0 comments on commit e12cdbc

Please sign in to comment.