Skip to content

Commit 2736b71

Browse files
fix: CSS for older browsers
1 parent e7ccda5 commit 2736b71

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎layouts/partials/essentials/style.html‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,48 @@
4545

4646
{{ $stylesLazy = $stylesLazy | resources.Concat "css/style-lazy.css" }}
4747

48+
{{/* Tailwind v4 output (cascade layers, nesting, oklch, range media queries) is
49+
ignored by old browsers such as the PocketBook e-reader. Build a transpiled copy
50+
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 }}
53+
4854
{{ if hugo.IsProduction }}
4955
{{ $styles = $styles | minify | fingerprint }}
5056
{{ $stylesLazy = $stylesLazy | minify | fingerprint }}
57+
{{ $stylesLegacy = $stylesLegacy | minify | fingerprint }}
5158
{{ end }}
5259

5360

5461
<!-- link main style -->
5562
<link
63+
id="main-style"
5664
href="{{ $styles.RelPermalink }}"
5765
integrity="{{ $styles.Data.Integrity }}"
5866
rel="stylesheet" />
5967

6068
<!-- link lazy style -->
6169
<link
70+
id="lazy-style"
6271
defer
6372
async
6473
rel="stylesheet"
6574
href="{{ $stylesLazy.RelPermalink }}"
6675
integrity="{{ $stylesLazy.Data.Integrity }}"
6776
media="print"
6877
onload="this.media='all'; this.onload=null;" />
78+
79+
<!-- swap to legacy style (includes the lazy style) if cascade layers are unsupported;
80+
force with ?legacy-css -->
81+
<script>
82+
if (!window.CSSLayerBlockRule || /[?&]legacy-css\b/.test(location.search)) {
83+
var lazyStyle = document.getElementById("lazy-style");
84+
var legacyStyle = document.createElement("link");
85+
legacyStyle.rel = "stylesheet";
86+
legacyStyle.href = "{{ $stylesLegacy.RelPermalink }}";
87+
lazyStyle.parentNode.insertBefore(legacyStyle, lazyStyle);
88+
lazyStyle.onload = null;
89+
lazyStyle.media = "not all";
90+
document.getElementById("main-style").media = "not all";
91+
}
92+
</script>

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
"autoprefixer": "^10.4.21",
3131
"caniuse-lite": "^1.0.30001724",
3232
"postcss": "^8.5.6",
33+
"postcss-cli": "^12.0.0",
34+
"postcss-preset-env": "^11.5.4",
3335
"prettier": "^3.5.3",
3436
"prettier-plugin-go-template": "0.0.15",
3537
"prettier-plugin-tailwindcss": "^0.6.11",

0 commit comments

Comments
 (0)