diff --git a/assets/css/critical.css b/assets/css/critical.css new file mode 100644 index 0000000..4a771dd --- /dev/null +++ b/assets/css/critical.css @@ -0,0 +1,29 @@ +/* + * Critical CSS — inlined into
via partials/head/critical-css.html. + * Keep this file small: it is rendered on every page before main.css loads. + * + * Currently scoped to text-selection highlighting so the chosen color shows + * even before the main bundle is parsed. + */ + +*::selection { + background-color: var(--color-primary, #4a90e2) !important; + color: var(--color-white, #ffffff) !important; + text-shadow: none !important; +} + +*::-moz-selection { + background-color: var(--color-primary, #4a90e2) !important; + color: var(--color-white, #ffffff) !important; + text-shadow: none !important; +} + +html[data-theme="dark"] *::selection { + background-color: #e9996b !important; + color: #1a2633 !important; +} + +html[data-theme="dark"] *::-moz-selection { + background-color: #e9996b !important; + color: #1a2633 !important; +} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index a2d894a..8c331d6 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,89 +1,44 @@ - - {{/* SEO Critical Resources - Must come first */}} - {{ partial "seo/preload-resources.html" . }} - - {{/* Consolidated Meta Tags with SEO */}} - {{ partial "head/meta.html" . }} - - {{/* Structured Data */}} - {{ partial "seo/schema-org.html" . }} - - - {{ partial "head/favicons.html" . }} - - - {{ partial "head/critical-css.html" . }} - - - {{ partial "head/styles.html" . }} - - {{/* Math Support - Load early for better rendering */}} - {{- if .Params.math -}} - - - - - - - - - {{- end -}} +{{/* + head.html — emits CHILDREN ONLY. - - {{ with site.Params.seo.google_site_verification }} - - {{ end }} - {{ with site.Params.seo.bing_verification }} - - {{ end }} - {{ with site.Params.seo.yandex_verification }} - - {{ end }} + Ownership: layouts/_default/baseof.html opens and closes . + Do NOT add a literal / here, otherwise the document would + contain nested heads. +*/}} - - {{ partial "analytics.html" . }} +{{/* SEO Critical Resources - Must come first */}} +{{ partial "seo/preload-resources.html" . }} - - {{ with resources.Get "js/main.js" }} - {{ $mainJS := . | js.Build | minify | fingerprint }} - - {{ end }} - - - {{ $pdfJS := resources.Get "js/pdf-generator.js" | minify | fingerprint }} - - - - {{ $scrollbarFadeJS := resources.Get "js/scrollbar-fade.js" | minify }} - +{{/* Consolidated Meta Tags with SEO (cached per URL — meta varies per page) */}} +{{ partialCached "head/meta.html" . .RelPermalink }} - {{/* Math rendering scripts - Load after DOM is ready */}} - {{- if .Params.math -}} - - +{{/* Structured Data */}} +{{ partial "seo/schema-org.html" . }} - - + +{{ partial "head/favicons.html" . }} - - + +{{ partial "head/critical-css.html" . }} - - - {{- end -}} - \ No newline at end of file + +{{ partial "head/styles.html" . }} + +{{/* TODO: replaced by Unit 11 katex partial — assets/js/katex-init.js + head/katex.html */}} + + +{{ with site.Params.seo.google_site_verification }} + +{{ end }} +{{ with site.Params.seo.bing_verification }} + +{{ end }} +{{ with site.Params.seo.yandex_verification }} + +{{ end }} + + +{{ partial "analytics.html" . }} + + +{{ partial "head/js.html" . }} diff --git a/layouts/partials/head/critical-css.html b/layouts/partials/head/critical-css.html index 5f9a844..b753cda 100644 --- a/layouts/partials/head/critical-css.html +++ b/layouts/partials/head/critical-css.html @@ -1,40 +1,15 @@ - +{{/* + critical-css.html — inlines the canonical theme-init JS (assets/js/critical.js) + and the small critical CSS bundle (assets/css/critical.css) into . + + This is the SINGLE place that emits the theme-init script. Other partials + must not duplicate the localStorage/data-theme bootstrap. +*/}} {{ $criticalJS := resources.Get "js/critical.js" | js.Build | minify }} - +{{ with resources.Get "css/critical.css" }} + {{ $criticalCSS := . | minify }} + +{{ end }} diff --git a/layouts/partials/head/js.html b/layouts/partials/head/js.html index 88f92fd..23f982f 100644 --- a/layouts/partials/head/js.html +++ b/layouts/partials/head/js.html @@ -1,26 +1,24 @@ - - +{{/* + js.html — application JS bundles. Theme-init is handled in critical-css.html + via assets/js/critical.js, do not duplicate it here. -{{- with resources.Get "js/main.js" }} - {{- if eq hugo.Environment "development" }} - {{- with . | js.Build }} - - {{- end }} - {{- else }} - {{- $opts := dict "minify" true }} - {{- with . | js.Build $opts | fingerprint }} - - {{- end }} + Production: minify, drop console/debugger, fingerprint with SRI. + Development: external sourceMap, no minify, no SRI (faster rebuilds). +*/}} + +{{- $jsOpts := dict "sourceMap" "external" -}} +{{- if hugo.IsProduction -}} + {{- $jsOpts = dict "minify" true "drop" (slice "console" "debugger") -}} +{{- end -}} + +{{- range (slice "js/main.js" "js/pdf-generator.js" "js/scrollbar-fade.js") }} + {{- with resources.Get . }} + {{- $built := . | js.Build $jsOpts -}} + {{- if hugo.IsProduction -}} + {{- $built = $built | fingerprint -}} + + {{- else -}} + + {{- end -}} {{- end }} {{- end }} diff --git a/layouts/partials/head/meta.html b/layouts/partials/head/meta.html index c210914..caf4435 100644 --- a/layouts/partials/head/meta.html +++ b/layouts/partials/head/meta.html @@ -3,8 +3,20 @@ - - +{{/* + Content Security Policy. + - Configurable via site.Params.security.csp (whole policy string). + - Default keeps 'unsafe-inline' on script-src because critical-css.html + inlines theme-init JS via safeJS, and on style-src for the inlined + critical CSS