From 1c31c5eaf533ff709f8bd825485b5699880da899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 9 Jun 2024 15:55:18 +0200 Subject: [PATCH] Use defer to load styles A new feature coming in next Hugo. See https://github.com/gohugoio/hugo/pull/12587 --- .hugo_build.lock | 0 hugo.toml | 30 ++++++++++++------------------ layouts/_default/baseof.html | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 26 deletions(-) delete mode 100644 .hugo_build.lock diff --git a/.hugo_build.lock b/.hugo_build.lock deleted file mode 100644 index e69de29..0000000 diff --git a/hugo.toml b/hugo.toml index a240f7c..8faf22d 100644 --- a/hugo.toml +++ b/hugo.toml @@ -5,25 +5,19 @@ disableKinds = ["page", "section", "taxonomy", "term"] [module] [module.hugoVersion] extended = false - min = "0.112.0" + min = "0.128.0" [[module.mounts]] source = "assets" target = "assets" [[module.mounts]] - source = "hugo_stats.json" - target = "assets/watching/hugo_stats.json" - -[build] - writeStats = true - [[build.cachebusters]] - source = "assets/watching/hugo_stats\\.json" - target = "styles\\.css" - [[build.cachebusters]] - source = "(postcss|tailwind)\\.config\\.js" - target = "css" - [[build.cachebusters]] - source = "assets/.*\\.(js|ts|jsx|tsx)" - target = "js" - [[build.cachebusters]] - source = "assets/.*\\.(.*)$" - target = "$1" + source = "hugo_stats.json" + target = "assets/notwatching/hugo_stats.json" + disableWatch = true +[build.buildStats] + enable = true +[[build.cachebusters]] + source = "assets/notwatching/hugo_stats\\.json" + target = "styles\\.css" +[[build.cachebusters]] + source = "(postcss|tailwind)\\.config\\.js" + target = "css" diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index cf8c4af..66b624d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -1,4 +1,4 @@ - + @@ -6,14 +6,17 @@ {{ .Title }} - {{/* styles */}} - {{ $options := dict "inlineImports" true }} - {{ $styles := resources.Get "css/styles.css" }} - {{ $styles = $styles | resources.PostCSS $options }} - {{ if hugo.IsProduction }} - {{ $styles = $styles | minify | fingerprint | resources.PostProcess }} + {{ with (templates.Defer (dict "key" "styles" "data" "foo")) }} + {{ warnf "deferred: %s" . }} + {{ $options := dict "inlineImports" true }} + {{ $styles := resources.Get "css/styles.css" }} + {{ $styles = $styles | resources.PostCSS $options }} + {{ if hugo.IsProduction }} + {{ $styles = $styles | minify | fingerprint }} + {{ end }} + {{ end }} - +