|
45 | 45 |
|
46 | 46 | {{ $stylesLazy = $stylesLazy | resources.Concat "css/style-lazy.css" }} |
47 | 47 |
|
| 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 | + |
48 | 54 | {{ if hugo.IsProduction }} |
49 | 55 | {{ $styles = $styles | minify | fingerprint }} |
50 | 56 | {{ $stylesLazy = $stylesLazy | minify | fingerprint }} |
| 57 | + {{ $stylesLegacy = $stylesLegacy | minify | fingerprint }} |
51 | 58 | {{ end }} |
52 | 59 |
|
53 | 60 |
|
54 | 61 | <!-- link main style --> |
55 | 62 | <link |
| 63 | + id="main-style" |
56 | 64 | href="{{ $styles.RelPermalink }}" |
57 | 65 | integrity="{{ $styles.Data.Integrity }}" |
58 | 66 | rel="stylesheet" /> |
59 | 67 |
|
60 | 68 | <!-- link lazy style --> |
61 | 69 | <link |
| 70 | + id="lazy-style" |
62 | 71 | defer |
63 | 72 | async |
64 | 73 | rel="stylesheet" |
65 | 74 | href="{{ $stylesLazy.RelPermalink }}" |
66 | 75 | integrity="{{ $stylesLazy.Data.Integrity }}" |
67 | 76 | media="print" |
68 | 77 | 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> |
0 commit comments