Skip to content

Commit

Permalink
perf: allow specifying a partial to directly include the desired te…
Browse files Browse the repository at this point in the history
…mplate, using the current page as the context (#60)
  • Loading branch information
razonyang authored Jun 14, 2024
1 parent 8541aa8 commit 4ea2769
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
19 changes: 12 additions & 7 deletions layouts/partials/hugopress/functions/render-hooks.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
{{- $page := .Page }}
{{- $modules := partialCached "hugopress/functions/modules" $name $name }}
{{- $total := len $modules }}
{{- $ctx := $page }}
{{- range $modules }}
{{- $ctx := dict
"Page" $page
"Total" $total
"HasPrev" ._hasPrev
"HasNext" ._hasNext
"Index" ._index
}}
{{- if site.Params.hugopress.debug }}
{{- warnf "[hugopress] [%s] rendering hook: %q." .module .name }}
{{- end }}
{{- if .direct }}
{{- $ctx = $page }}
{{- else }}
{{- $ctx = dict
"Page" $page
"Total" $total
"HasPrev" ._hasPrev
"HasNext" ._hasNext
"Index" ._index
}}
{{- end }}
{{- if .cacheable }}
{{- if ne .cache_key nil }}
{{- partialCached .partial $ctx (index (apply (slice 0) .cache_key) 0) }}
Expand Down
12 changes: 10 additions & 2 deletions layouts/partials/hugopress/functions/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,23 @@
{{- end }}
{{- continue }}
{{- end }}
{{- $partial := printf "hugopress/modules/%s/hooks/%s" $moduleName $name }}
{{- $partial := default "" .partial }}
{{/* $direct indicates whether to include partial with page variable. */}}
{{- $direct := false }}
{{- if eq $partial "" }}
{{- $partial = printf "hugopress/modules/%s/hooks/%s" $moduleName $name }}
{{- else }}
{{- $direct = true }}
{{- end }}
{{- if not (partialCached "hugopress/functions/partial-exists" $partial $partial) }}
{{- warnf "[hugopress] [%s] hook does't exist: layouts/partials/%s.html" $moduleName $partial }}
{{- continue }}
{{- end }}
{{- $option = merge $option (dict
"name" $name
"module" $moduleName
"partial" $partial)
"partial" $partial
"direct" $direct)
}}
{{/* Transform cache keys only once. */}}
{{- range slice "cache_param_key" "cache_site_param_key" }}
Expand Down

0 comments on commit 4ea2769

Please sign in to comment.