{{- /* js.html (partial): Manages the loading of JavaScript assets before the
. - All scripts are processed for development (unminified) and production (minified, fingerprinted, with SRI) environments. Repo: https://github.com/oxypteros/alpha */ -}} {{- /* `alpha-tail.js`: - Processed by Hugo templates for i18n string replacement and conditional feature loading. - Built using js.Build. */ -}} {{- $data := dict "Lang" .Site.Language.Lang "Site" .Site -}} {{- with resources.Get "alpha/js/alpha-tail.js" | resources.ExecuteAsTemplate (printf "alpha-tail-%s.js" .Site.Language.Lang) $data -}} {{- $content := .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 }} {{- /* `alpha-contact.js`: - Processed by Hugo templates for i18n string replacement and conditional feature loading. - Built using js.Build. */ -}} {{- if .Page.HasShortcode "contact" }} {{- $data := dict "Lang" .Site.Language.Lang "Site" .Site -}} {{- with resources.Get "alpha/js/alpha-contact.js" | resources.ExecuteAsTemplate (printf "alpha-contact-%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 }} {{- end }} {{- /* `custom-tail.js`: - Allows users to inject their own JavaScript into the of every page. - The script is only included if the `custom-tail.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-tail.js` in the root `/assets/js/`. */ -}} {{- with resources.Get "js/custom-tail.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 }} {{- /* If Goatcounter is enabled (`params.toml`) will be conditionally loaded only on PRODUCTION env */}} {{- if .Site.Params.goatcounter_prefix }} {{ $goatcounter := .Site.Params.goatcounter_prefix }} {{- with resources.Get "js/goatcounter.js" }} {{- if eq hugo.Environment "development" -}} {{- else }} {{- $opts := dict "minify" true }} {{- with . | js.Build $opts }} {{- end }} {{- end }} {{- end }} {{- end }}