From 88bd6157686472aff1a2397c7f66b5f13c5c4d40 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Wed, 20 Aug 2025 23:54:10 +0100 Subject: [PATCH] build: unify vendor pipeline, externalize head JS, switch docs to pnpm - Remove modules/blox-tailwind/vite.config.js; use root Vite vendor task - Vendor alpinejs and markmap; add vendor-libs.js stub - Replace inline head scripts with CSP-friendly hb-head.js; add font preload + fingerprint - Update scripts/docs to pnpm; remove unused @tailwindcss/vite --- modules/blox-tailwind/assets/js/hb-head.js | 7 +++ modules/blox-tailwind/assets/js/hb-init.js | 44 +++++++++++++++ .../blox-tailwind/assets/js/vendor-libs.js | 5 ++ .../layouts/_partials/site_head.html | 55 +++---------------- modules/blox-tailwind/package.json | 2 +- modules/blox-tailwind/vite.config.js | 43 --------------- package.json | 4 +- vite.config.js | 10 +++- 8 files changed, 74 insertions(+), 96 deletions(-) create mode 100644 modules/blox-tailwind/assets/js/hb-head.js create mode 100644 modules/blox-tailwind/assets/js/hb-init.js create mode 100644 modules/blox-tailwind/assets/js/vendor-libs.js delete mode 100644 modules/blox-tailwind/vite.config.js diff --git a/modules/blox-tailwind/assets/js/hb-head.js b/modules/blox-tailwind/assets/js/hb-head.js new file mode 100644 index 00000000..71b60800 --- /dev/null +++ b/modules/blox-tailwind/assets/js/hb-head.js @@ -0,0 +1,7 @@ +import { initTheme, applyHugoStyleFixes } from './hb-init.js' + +initTheme() +applyHugoStyleFixes() + + + diff --git a/modules/blox-tailwind/assets/js/hb-init.js b/modules/blox-tailwind/assets/js/hb-init.js new file mode 100644 index 00000000..f221c2f1 --- /dev/null +++ b/modules/blox-tailwind/assets/js/hb-init.js @@ -0,0 +1,44 @@ +// Hugo Blox JS Global Init (CSP-friendly) +export function initTheme() { + const root = document.documentElement; + const defaultTheme = root.dataset.wcThemeDefault; + const setDark = () => { root.classList.add('dark'); root.style.colorScheme = 'dark'; }; + const setLight = () => { root.classList.remove('dark'); root.style.colorScheme = 'light'; }; + + if ('wc-color-theme' in localStorage) { + localStorage.getItem('wc-color-theme') === 'dark' ? setDark() : setLight(); + } else { + if (defaultTheme === 'dark') setDark(); + else if (defaultTheme === 'light') setLight(); + else if (defaultTheme === 'system') { + window.matchMedia('(prefers-color-scheme: dark)').matches ? setDark() : setLight(); + } + } +} + +export function applyHugoStyleFixes() { + document.addEventListener('DOMContentLoaded', function () { + const checkboxes = document.querySelectorAll("li input[type='checkbox'][disabled]"); + checkboxes.forEach((e) => { + const parent = e.parentElement?.parentElement; + if (parent) parent.classList.add('task-list'); + }); + + const liNodes = document.querySelectorAll('.task-list li'); + liNodes.forEach((nodes) => { + const textNodes = Array.from(nodes.childNodes).filter( + (node) => node.nodeType === 3 && node.textContent && node.textContent.trim().length > 1, + ); + if (textNodes.length > 0) { + const span = document.createElement('label'); + textNodes[0].after(span); + const input = nodes.querySelector("input[type='checkbox']"); + if (input) span.appendChild(input); + span.appendChild(textNodes[0]); + } + }); + }); +} + + + diff --git a/modules/blox-tailwind/assets/js/vendor-libs.js b/modules/blox-tailwind/assets/js/vendor-libs.js new file mode 100644 index 00000000..51eb3ef6 --- /dev/null +++ b/modules/blox-tailwind/assets/js/vendor-libs.js @@ -0,0 +1,5 @@ +// Dummy entry for Vite lib mode. We copy vendor libraries via vite-plugin-static-copy. +export default {} + + + diff --git a/modules/blox-tailwind/layouts/_partials/site_head.html b/modules/blox-tailwind/layouts/_partials/site_head.html index a5ac3962..2faa88c0 100644 --- a/modules/blox-tailwind/layouts/_partials/site_head.html +++ b/modules/blox-tailwind/layouts/_partials/site_head.html @@ -76,54 +76,12 @@ {{ end }} - - - + {{/* Externalized init scripts for CSP-friendly head */}} + {{- $hb_head := resources.Get "js/hb-head.js" | js.Build | resources.Minify -}} + {{- if hugo.IsProduction -}} + {{- $hb_head = $hb_head | fingerprint "sha256" -}} + {{- end -}} + {{/* Analytics & Verification */}} {{/* !CACHED! All analytics and verification code is at site level */}} @@ -218,6 +176,7 @@ {{ $font_type = "woff2" }} {{end}} {{ $font := resources.Get (printf "dist/font/%s" $font_file) }} +