Skip to content

Commit 66acd68

Browse files
committed
skip missing assets
1 parent 5ec3ca5 commit 66acd68

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎layouts/partials/essentials/style.html‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,19 @@
4848
{{/* Tailwind v4 output (cascade layers, nesting, oklch, range media queries) is
4949
ignored by old browsers such as the PocketBook e-reader. Build a transpiled copy
5050
for them, see postcss.config.js and assets/css/legacy.css. The lazy styles are
51-
bundled in, so their unlayered rules keep winning over Tailwind's layers. */}}
52-
{{ $stylesLegacy := slice $styles $stylesLazy (resources.Get "css/legacy.css") | resources.Concat "css/style-legacy.css" | css.PostCSS }}
51+
bundled in, so their unlayered rules keep winning over Tailwind's layers.
52+
Skipped if assets/css/legacy.css is missing. */}}
53+
{{ $stylesLegacy := false }}
54+
{{ with resources.Get "css/legacy.css" }}
55+
{{ $stylesLegacy = slice $styles $stylesLazy . | resources.Concat "css/style-legacy.css" | css.PostCSS }}
56+
{{ end }}
5357

5458
{{ if hugo.IsProduction }}
5559
{{ $styles = $styles | minify | fingerprint }}
5660
{{ $stylesLazy = $stylesLazy | minify | fingerprint }}
57-
{{ $stylesLegacy = $stylesLegacy | minify | fingerprint }}
61+
{{ with $stylesLegacy }}
62+
{{ $stylesLegacy = . | minify | fingerprint }}
63+
{{ end }}
5864
{{ end }}
5965

6066

@@ -78,15 +84,17 @@
7884

7985
<!-- swap to legacy style (includes the lazy style) if cascade layers are unsupported;
8086
force with ?legacy-css -->
87+
{{ with $stylesLegacy }}
8188
<script>
8289
if (!window.CSSLayerBlockRule || /[?&]legacy-css\b/.test(location.search)) {
8390
var lazyStyle = document.getElementById("lazy-style");
8491
var legacyStyle = document.createElement("link");
8592
legacyStyle.rel = "stylesheet";
86-
legacyStyle.href = "{{ $stylesLegacy.RelPermalink }}";
93+
legacyStyle.href = "{{ .RelPermalink }}";
8794
lazyStyle.parentNode.insertBefore(legacyStyle, lazyStyle);
8895
lazyStyle.onload = null;
8996
lazyStyle.media = "not all";
9097
document.getElementById("main-style").media = "not all";
9198
}
9299
</script>
100+
{{ end }}

0 commit comments

Comments
 (0)