From 72a4cedcdccbf111865a2c2621c6dafe10314796 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Mon, 25 Aug 2025 18:23:50 +0100 Subject: [PATCH] perf(init): faster site builds optimize site.AllPages with Site.Scratch guard and scope to pages only - Add Site.Scratch guard to run init logic only once per build - Limit .Content pre-warming to pages (Kind == 'page') to reduce overhead - Preserve Hugo concurrency workaround for Page.Store and backlinks - Maintain existing block configuration preloading for landing pages --- .../blox-tailwind/layouts/_partials/init.html | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/blox-tailwind/layouts/_partials/init.html b/modules/blox-tailwind/layouts/_partials/init.html index 47432d65..7504d43a 100644 --- a/modules/blox-tailwind/layouts/_partials/init.html +++ b/modules/blox-tailwind/layouts/_partials/init.html @@ -1,9 +1,18 @@ {{/* Workaround Hugo concurrency issues (e.g. not detecting Page.Store variables) */}} {{/* Use cases: Page.Store use within shortcodes, blox, and backlinks. */}} {{/* See https://discourse.gohugo.io/t/persisting-data-across-the-build-of-a-site/41114/6 */}} -{{- range $page := site.AllPages }} - {{- $noop := .Content }} - {{ if eq .Type "landing" }} +{{ $scr := site.Scratch }} +{{ if not ($scr.Get "hb_init_done") }} + {{ $scr.Set "hb_init_done" true }} + + {{/* Pre-warm only content pages so Page.Store/backlinks are populated deterministically */}} + {{- range where site.Pages "Kind" "page" -}} + {{- $ := .Content -}} + {{- end -}} + + {{/* Preload block configs for landing pages */}} + {{- range where site.Pages "Type" "landing" -}} + {{ $page := . }} {{ range $index, $block := .Params.sections }} {{/* Do not show sections intended only for the demo site. */}} {{ if or (not $block.demo) ($block.demo | and (eq (os.Getenv "HUGO_BLOX_DEMO") "true")) }} @@ -13,12 +22,11 @@ {{ end }} {{ $widget_config_file := printf "blox/%s--CONFIG.html" $block_type }} {{ if templates.Exists (printf "_partials/%s" $widget_config_file) }} - {{/* warnf "Loading blox config at %s" $widget_config_file */}} {{ $hash_id := $block.id | default (printf "section-%s" (replace $block_type "." "-")) }} {{ $widget_args := dict "wcPage" $page "wcBlock" $block "wcIdentifier" $hash_id }} {{ partial $widget_config_file $widget_args }} - {{end}} + {{ end }} {{ end }} {{ end }} {{- end -}} -{{- end -}} +{{ end }}