From baf0eca20ed0055cd3624a8d50a560943fcb3266 Mon Sep 17 00:00:00 2001 From: stradichenko Date: Sun, 26 Apr 2026 15:01:24 +0200 Subject: [PATCH] Unit 6: head/* partials cleanup - head.html: drop the inline duplicated theme-init - {{ 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