{{- /* js.html (partial): Manages the loading of JavaScript assets in the . Features: - Build and append the main application script, which is processed for multilingual support and conditionally includes features based on site configuration. - Append the Pagefind UI script, if Pagefind is enabled. - Append an user-defined `custom-head.js` for adding custom JavaScript to the . - All scripts are processed for development (unminified) and production (minified, fingerprinted, with SRI) environments. Repo: https://github.com/oxypteros/alpha */ -}} {{- /* `alpha-head.js`: - Processed by Hugo templates for i18n string replacement and conditional feature loading. - Built using js.Build and loaded as an ES module. */ -}} {{- $data := dict "Lang" .Site.Language.Lang "Site" .Site -}} {{- with resources.Get "alpha/js/alpha-head.js" | resources.ExecuteAsTemplate (printf "alpha-head-%s.js" .Site.Language.Lang) $data -}} {{- if eq hugo.Environment "development" -}} {{- with . | js.Build }} {{- end }} {{- else }} {{- $opts := dict "minify" true }} {{- with . | js.Build $opts | fingerprint }} {{- end }} {{- end }} {{- end }} {{- /* `pagefind-ui.js`: - Loaded if Pagefind search is enabled in site parameters. - Uses `defer` to ensure non-blocking loading. - Note: This script is typically provided by the Pagefind installation and is expected to be available at `public/pagefind/pagefind-ui.js`. */ -}} {{- if eq .Site.Params.pagefind_enabled true }} {{- end }} {{- /* `custom-head.js`: - Allows users to inject their own JavaScript into the of every page. - The script is only included if the `custom-head.js` file exists and contains code beyond a default JSDoc-style comment block (pre-defined). - Processed by js.Build for minification and fingerprinting in production. - Loaded with `defer` to ensure non-blocking loading. - Users should copy the `custom-head.js` in the root `/assets/js/`. */ -}} {{- with resources.Get "js/custom-head.js" }} {{- $content := .Content | strings.TrimSpace -}} {{- /* Remove pre-defined JSDoc-style comment blocks */}} {{- $content := replaceRE `(?s)/\*\*\*.*?\*/` "" $content | strings.TrimSpace -}} {{- if $content -}} {{- if eq hugo.Environment "development" -}} {{- with . | js.Build }} {{- end }} {{- else }} {{- $opts := dict "minify" true }} {{- with . | js.Build $opts | fingerprint }} {{- end }} {{- end }} {{- end }} {{- end }}