From 0af8be439f761b4f06448a119b674de03a890444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 25 Jun 2024 19:04:52 +0200 Subject: [PATCH] Update Defer.md --- content/en/functions/templates/Defer.md | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/content/en/functions/templates/Defer.md b/content/en/functions/templates/Defer.md index eb69b86ee2..a7670c7dfc 100644 --- a/content/en/functions/templates/Defer.md +++ b/content/en/functions/templates/Defer.md @@ -17,14 +17,28 @@ aliases: [/functions/templates.defer] In some rare use cases, you may need to defer the execution of a template until after all sites and output formats have been rendered. One such example could be [TailwindCSS](https://github.com/bep/hugo-starter-tailwind-basic) using the output of [hugo_stats.json](https://gohugo.io/getting-started/configuration/#configure-build) to determine which classes and other HTML identifiers are being used in the final output: ```go-html-template -{{ with (templates.Defer (dict "key" "global-styles" )) }} - {{ $options := dict "inlineImports" true }} - {{ $styles := resources.Get "css/styles.css" }} - {{ $styles = $styles | resources.PostCSS $options }} - {{ if hugo.IsProduction }} - {{ $styles = $styles | minify | fingerprint }} +{{ with (templates.Defer (dict "key" "global")) }} + {{ $t := debug.Timer "tailwindcss" }} + {{ with resources.Get "css/styles.css" }} + {{ $opts := dict + "inlineImports" true + "optimize" hugo.IsProduction + }} + {{ with . | css.TailwindCSS $opts }} + {{ if hugo.IsDevelopment }} + + {{ else }} + {{ with . | minify | fingerprint }} + + {{ end }} {{ end }} - + {{ end }} + {{ end }} + {{ $t.Stop }} {{ end }} ```