Skip to content

Commit

Permalink
Use defer to load styles
Browse files Browse the repository at this point in the history
A new feature coming in next Hugo.

See gohugoio/hugo#12587
  • Loading branch information
bep committed Jun 21, 2024
1 parent 4ce5197 commit 0261138
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Empty file removed .hugo_build.lock
Empty file.
13 changes: 6 additions & 7 deletions hugo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@ disableKinds = ["page", "section", "taxonomy", "term"]
source = "assets"
target = "assets"
[[module.mounts]]
source = "hugo_stats.json"
target = "assets/watching/hugo_stats.json"
source = "hugo_stats.json"
target = "assets/notwatching/hugo_stats.json"
disableWatch = true

[build]
writeStats = true
writeStats = true
useResourceCacheWhen = 'never'
[[build.cachebusters]]
source = "assets/watching/hugo_stats\\.json"
source = "assets/notwatching/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"
5 changes: 2 additions & 3 deletions hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"head",
"html",
"li",
"link",
"meta",
"ol",
"p",
Expand All @@ -26,7 +25,7 @@
"ul"
],
"classes": [
"bg-[green]",
"bg-[orange]",
"container",
"highlight",
"lg:mx-auto",
Expand All @@ -53,4 +52,4 @@
"this-is-a-header"
]
}
}
}
19 changes: 11 additions & 8 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>
{{ .Title }}
</title>
<meta name="description" content="{{ .Description }}" />
{{/* 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 (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 }}
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />
{{ end }}
<link href="{{ $styles.RelPermalink }}" rel="stylesheet" />

</head>
<body class="my-10">
<div class="container px-4 lg:mx-auto">
Expand Down
2 changes: 1 addition & 1 deletion layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h1>Tailwind 3 Hugo Starter</h1>

<h2 class="text-4xl">Testing Tailwind 3 Features</h2>
<div>
<button class="bg-[green] p-4">Share on Twitter</button>
<button class="bg-[orange] p-4">Share on Twitter</button>
</div>

<h2 class="text-4xl">Markdowns: {{ .Title }}</h2>
Expand Down

0 comments on commit 0261138

Please sign in to comment.