Initial commit: Rapport Website (Hugo + Hextra)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
{{- /* Asciinema */ -}}
|
||||
|
||||
{{- $asciinemaBase := "" -}}
|
||||
{{- $useDefaultCdn := true -}}
|
||||
{{- with site.Params.asciinema.base -}}
|
||||
{{- $asciinemaBase = . -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $asciinemaJsAsset := "" -}}
|
||||
{{- with site.Params.asciinema.js -}}
|
||||
{{- $asciinemaJsAsset = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $asciinemaCssAsset := "" -}}
|
||||
{{- with site.Params.asciinema.css -}}
|
||||
{{- $asciinemaCssAsset = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* If only js/css is set without base, use local asset loading */ -}}
|
||||
{{- if and $useDefaultCdn (or (ne $asciinemaJsAsset "") (ne $asciinemaCssAsset "")) -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Set default CDN base if needed */ -}}
|
||||
{{- if $useDefaultCdn -}}
|
||||
{{- $asciinemaBase = "https://cdn.jsdelivr.net/npm/asciinema-player@latest/dist/bundle" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $isRemoteBase := or (strings.HasPrefix $asciinemaBase "http://") (strings.HasPrefix $asciinemaBase "https://") -}}
|
||||
{{- $minSuffix := cond hugo.IsProduction ".min" "" -}}
|
||||
|
||||
{{- /* CSS retrieval: get raw CSS from either local asset or remote, then process */ -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $cssPath := cond (ne $asciinemaCssAsset "") $asciinemaCssAsset "asciinema-player.css" -}}
|
||||
{{- $asciinemaCssUrl := urls.JoinPath $asciinemaBase $cssPath -}}
|
||||
{{- with try (resources.GetRemote $asciinemaCssUrl) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "Could not retrieve Asciinema css file from %s. Reason: %s." $asciinemaCssUrl . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- with resources.Copy "css/asciinema-player.css" . -}}
|
||||
{{- $asciinemaCss := . | fingerprint -}}
|
||||
<link rel="stylesheet" href="{{ $asciinemaCss.RelPermalink }}" integrity="{{ $asciinemaCss.Data.Integrity }}" crossorigin="anonymous" />
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else if $asciinemaCssAsset -}}
|
||||
{{- with resources.Get $asciinemaCssAsset -}}
|
||||
{{- $asciinemaCss := . | fingerprint -}}
|
||||
<link rel="stylesheet" href="{{ $asciinemaCss.RelPermalink }}" integrity="{{ $asciinemaCss.Data.Integrity }}" crossorigin="anonymous" />
|
||||
{{- else -}}
|
||||
{{- errorf "Asciinema css asset not found at %q" $asciinemaCssAsset -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* JS retrieval: get raw JS from either local asset or remote, then process */ -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $jsPath := cond (ne $asciinemaJsAsset "") $asciinemaJsAsset (printf "asciinema-player%s.js" $minSuffix) -}}
|
||||
{{- $asciinemaJsUrl := urls.JoinPath $asciinemaBase $jsPath -}}
|
||||
{{- with try (resources.GetRemote $asciinemaJsUrl) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "Could not retrieve Asciinema js file from %s. Reason: %s." $asciinemaJsUrl . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- with resources.Copy (printf "js/asciinema-player%s.js" $minSuffix) . -}}
|
||||
{{- $asciinemaJs := . | fingerprint -}}
|
||||
<script defer src="{{ $asciinemaJs.RelPermalink }}" integrity="{{ $asciinemaJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else if $asciinemaJsAsset -}}
|
||||
{{- with resources.Get $asciinemaJsAsset -}}
|
||||
{{- $asciinemaJs := . | fingerprint -}}
|
||||
<script defer src="{{ $asciinemaJs.RelPermalink }}" integrity="{{ $asciinemaJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- else -}}
|
||||
{{- errorf "Asciinema js asset not found at %q" $asciinemaJsAsset -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
<script data-playback-time="{{ (T "playbackTime") | default "Playback time" }}">
|
||||
const playbackTimeLabel =
|
||||
document.currentScript?.getAttribute("data-playback-time") || "Playback time";
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
const observers = [];
|
||||
|
||||
const applyTimerA11y = (container) => {
|
||||
container.querySelectorAll(".ap-timer[role='textbox']").forEach((timer) => {
|
||||
if (!timer.getAttribute("aria-label")) {
|
||||
timer.setAttribute("aria-label", playbackTimeLabel);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Fix play button position issue
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `
|
||||
.ap-player .ap-overlay-start .ap-play-button span > svg {
|
||||
display: inline;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
// Initialize asciinema players
|
||||
document.querySelectorAll(".asciinema-player").forEach((el) => {
|
||||
const castFile = el.dataset.castFile;
|
||||
const theme = el.dataset.theme || "asciinema";
|
||||
const speed = parseFloat(el.dataset.speed) || 1;
|
||||
const autoplay = el.dataset.autoplay === "true";
|
||||
const loop = el.dataset.loop === "true";
|
||||
const poster = el.dataset.poster || "";
|
||||
const markers = el.dataset.markers ? JSON.parse(el.dataset.markers) : [];
|
||||
|
||||
// Create asciinema player
|
||||
if (window.AsciinemaPlayer) {
|
||||
window.AsciinemaPlayer.create(castFile, el, {
|
||||
theme: theme,
|
||||
speed: speed,
|
||||
autoplay: autoplay,
|
||||
loop: loop,
|
||||
poster: poster || undefined,
|
||||
markers: markers.length > 0 ? markers : undefined,
|
||||
controls: true, // Always show user controls (bottom control bar)
|
||||
idleTimeLimit: 2, // Limit terminal inactivity to 2 seconds (compress pauses longer than 2s)
|
||||
});
|
||||
applyTimerA11y(el);
|
||||
const observer = new MutationObserver(() => applyTimerA11y(el));
|
||||
observer.observe(el, { childList: true, subtree: true });
|
||||
observers.push(observer);
|
||||
}
|
||||
});
|
||||
|
||||
// Prevent lingering observers when navigating away.
|
||||
window.addEventListener(
|
||||
"pagehide",
|
||||
() => {
|
||||
observers.forEach((observer) => observer.disconnect());
|
||||
},
|
||||
{ once: true },
|
||||
);
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,10 @@
|
||||
{{- $scriptsBody := slice }}
|
||||
{{- range resources.Match "js/core/*.js" -}}
|
||||
{{ $scriptsBody = $scriptsBody | append (resources.ExecuteAsTemplate .Name $ .) }}
|
||||
{{- end -}}
|
||||
|
||||
{{- $scripts := $scriptsBody | resources.Concat "js/main.js" -}}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{- $scripts = $scripts | minify | fingerprint -}}
|
||||
{{- end -}}
|
||||
<script defer src="{{ $scripts.RelPermalink }}" integrity="{{ $scripts.Data.Integrity }}"></script>
|
||||
@@ -0,0 +1,92 @@
|
||||
{{- /* KaTeX CSS loader
|
||||
|
||||
Behavior (driven by site.params.math.katex):
|
||||
- base (remote URL) + optional css:
|
||||
- Construct remote CSS URL: "{{ base }}/{{ css | default "katex[.min].css" }}".
|
||||
- Fetch via resources.GetRemote, rewrite font URLs to "{{ base }}/fonts/...".
|
||||
- Build and fingerprint; emit <link rel="stylesheet" integrity>.
|
||||
- base (local path or not set) + css (asset path):
|
||||
- Read CSS from Hugo assets via resources.Get; DO NOT rewrite font URLs.
|
||||
- Build and fingerprint; emit <link rel="stylesheet" integrity>.
|
||||
- base (local path) only (no css):
|
||||
- Link directly to "{{ base }}/katex[.min].css" (no processing).
|
||||
- Nothing set:
|
||||
- Default to CDN latest base; same as remote path above.
|
||||
|
||||
Additional:
|
||||
- assets: optional list to publish extra assets. CSS/JS get tags with integrity (JS loads async).
|
||||
*/ -}}
|
||||
{{- $noop := .WordCount -}}
|
||||
|
||||
{{- $katexBase := "" -}}
|
||||
{{- with site.Params.math.katex.base -}}
|
||||
{{- $katexBase = . -}}
|
||||
{{- else -}}
|
||||
{{- if not site.Params.math.katex.css -}}
|
||||
{{- $katexBase = "https://cdn.jsdelivr.net/npm/katex@latest/dist" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $katexCssAsset := "" -}}
|
||||
{{- with site.Params.math.katex.css -}}
|
||||
{{- $katexCssAsset = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $s := newScratch -}}
|
||||
{{- $isRemoteBase := or (strings.HasPrefix $katexBase "http://") (strings.HasPrefix $katexBase "https://") -}}
|
||||
|
||||
{{- /* CSS retrieval consolidated: get raw CSS from either local asset or remote, then process once */ -}}
|
||||
{{- $minSuffix := cond hugo.IsProduction ".min" "" -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $cssPath := cond (ne $katexCssAsset "") $katexCssAsset (printf "katex%s.css" $minSuffix) -}}
|
||||
{{- $katexCssUrl := urls.JoinPath $katexBase $cssPath -}}
|
||||
{{- with try (resources.GetRemote $katexCssUrl) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "Could not retrieve KaTeX css file from %s. Reason: %s." $katexCssUrl . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- $s.Set "katexCssValue" .Content -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else if $katexCssAsset -}}
|
||||
{{- with resources.Get $katexCssAsset -}}
|
||||
{{- $s.Set "katexCssValue" .Content -}}
|
||||
{{- else -}}
|
||||
{{- errorf "KaTeX css asset not found at %q" $katexCssAsset -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $s.Get "katexCssValue" -}}
|
||||
{{- $cssContent := . -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $fontPattern := "url(fonts/" -}}
|
||||
{{- $fontSub := printf "url(%s/" (urls.JoinPath $katexBase "fonts") -}}
|
||||
{{- $cssContent = strings.Replace $cssContent $fontPattern $fontSub -}}
|
||||
{{- end -}}
|
||||
{{- with resources.FromString (printf "css/katex%s.css" $minSuffix) $cssContent -}}
|
||||
{{- $css := . | fingerprint "sha512" -}}
|
||||
<link rel="stylesheet" href="{{ $css.RelPermalink }}" integrity="{{ $css.Data.Integrity }}" />
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- if not $isRemoteBase -}}
|
||||
{{- $cssPath := cond (ne $katexCssAsset "") $katexCssAsset (printf "katex%s.css" $minSuffix) -}}
|
||||
<link rel="stylesheet" href="{{ urls.JoinPath $katexBase $cssPath }}" />
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Optionally publish files (fonts, css, js, etc.) from assets and emit tags for css/js with integrity and crossorigin */ -}}
|
||||
{{- with site.Params.math.katex.assets -}}
|
||||
{{- range . -}}
|
||||
{{- with resources.Get . -}}
|
||||
{{- $name := .Name | lower -}}
|
||||
{{- if strings.HasSuffix $name ".css" -}}
|
||||
{{- $built := . | fingerprint "sha512" -}}
|
||||
<link rel="stylesheet" href="{{ $built.RelPermalink }}" integrity="{{ $built.Data.Integrity }}" crossorigin="anonymous" />
|
||||
{{- else if or (strings.HasSuffix $name ".js") (strings.HasSuffix $name ".mjs") -}}
|
||||
{{- $built := . | fingerprint "sha512" -}}
|
||||
<script src="{{ $built.RelPermalink }}" async integrity="{{ $built.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- else -}}
|
||||
{{- .Publish -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,20 @@
|
||||
{{/* MathJax */}}
|
||||
{{ $mathjaxJsUrl := "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js" -}}
|
||||
<script defer id="MathJax-script" src="{{ $mathjaxJsUrl }}" crossorigin="anonymous" async></script>
|
||||
<script>
|
||||
MathJax = {
|
||||
loader: {
|
||||
load: ["ui/safe"],
|
||||
},
|
||||
tex: {
|
||||
displayMath: [
|
||||
["\\[", "\\]"],
|
||||
["$$", "$$"],
|
||||
],
|
||||
inlineMath: [
|
||||
["\\(", "\\)"],
|
||||
["$", "$"],
|
||||
],
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -0,0 +1,85 @@
|
||||
{{- /* Medium Zoom */ -}}
|
||||
|
||||
{{- $zoomBase := "" -}}
|
||||
{{- $useDefaultCdn := true -}}
|
||||
{{- with site.Params.imageZoom.base -}}
|
||||
{{- $zoomBase = . -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $zoomJsAsset := "" -}}
|
||||
{{- with site.Params.imageZoom.js -}}
|
||||
{{- $zoomJsAsset = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* If only js is set without base, use local asset loading */ -}}
|
||||
{{- if and $useDefaultCdn (ne $zoomJsAsset "") -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Set default CDN base if needed */ -}}
|
||||
{{- if $useDefaultCdn -}}
|
||||
{{- $zoomBase = "https://cdn.jsdelivr.net/npm/medium-zoom@latest/dist" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $isRemoteBase := or (strings.HasPrefix $zoomBase "http://") (strings.HasPrefix $zoomBase "https://") -}}
|
||||
{{- $minSuffix := cond hugo.IsProduction ".min" "" -}}
|
||||
|
||||
{{- /* JS retrieval: get raw JS from either local asset or remote, then process */ -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $jsPath := cond (ne $zoomJsAsset "") $zoomJsAsset (printf "medium-zoom%s.js" $minSuffix) -}}
|
||||
{{- $zoomJsUrl := urls.JoinPath $zoomBase $jsPath -}}
|
||||
{{- with try (resources.GetRemote $zoomJsUrl) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "Could not retrieve Medium Zoom js file from %s. Reason: %s." $zoomJsUrl . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- with resources.Copy (printf "js/medium-zoom%s.js" $minSuffix) . -}}
|
||||
{{- $zoomJs := . | fingerprint -}}
|
||||
<script defer src="{{ $zoomJs.RelPermalink }}" integrity="{{ $zoomJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else if $zoomJsAsset -}}
|
||||
{{- with resources.Get $zoomJsAsset -}}
|
||||
{{- $zoomJs := . | fingerprint -}}
|
||||
<script defer src="{{ $zoomJs.RelPermalink }}" integrity="{{ $zoomJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- else -}}
|
||||
{{- errorf "Medium Zoom js asset not found at %q" $zoomJsAsset -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
if (!window.mediumZoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
const getOverlay = () => {
|
||||
return document.documentElement.classList.contains("dark")
|
||||
? "rgba(17, 17, 17, 0.98)"
|
||||
: "rgba(255, 255, 255, 0.98)";
|
||||
};
|
||||
|
||||
const zoom = window.mediumZoom("[data-zoomable]", {
|
||||
background: getOverlay(),
|
||||
});
|
||||
|
||||
const style = document.createElement("style");
|
||||
style.textContent = `
|
||||
.medium-zoom-overlay {
|
||||
z-index: 1000;
|
||||
}
|
||||
.medium-zoom-image--opened {
|
||||
z-index: 1001;
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(style);
|
||||
|
||||
new MutationObserver(() => {
|
||||
zoom.update({ background: getOverlay() });
|
||||
}).observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,79 @@
|
||||
{{- /* Mermaid */ -}}
|
||||
|
||||
{{- $mermaidBase := "" -}}
|
||||
{{- $useDefaultCdn := true -}}
|
||||
{{- with site.Params.mermaid.base -}}
|
||||
{{- $mermaidBase = . -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $mermaidJsAsset := "" -}}
|
||||
{{- with site.Params.mermaid.js -}}
|
||||
{{- $mermaidJsAsset = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* If only js is set without base, use local asset loading */ -}}
|
||||
{{- if and $useDefaultCdn (ne $mermaidJsAsset "") -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Set default CDN base if needed */ -}}
|
||||
{{- if $useDefaultCdn -}}
|
||||
{{- $mermaidBase = "https://cdn.jsdelivr.net/npm/mermaid@latest/dist" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $isRemoteBase := or (strings.HasPrefix $mermaidBase "http://") (strings.HasPrefix $mermaidBase "https://") -}}
|
||||
{{- $minSuffix := cond hugo.IsProduction ".min" "" -}}
|
||||
|
||||
{{- /* JS retrieval: get raw JS from either local asset or remote, then process */ -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $jsPath := cond (ne $mermaidJsAsset "") $mermaidJsAsset (printf "mermaid%s.js" $minSuffix) -}}
|
||||
{{- $mermaidJsUrl := urls.JoinPath $mermaidBase $jsPath -}}
|
||||
{{- with try (resources.GetRemote $mermaidJsUrl) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "Could not retrieve Mermaid js file from %s. Reason: %s." $mermaidJsUrl . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- with resources.Copy (printf "js/mermaid%s.js" $minSuffix) . -}}
|
||||
{{- $mermaidJs := . | fingerprint -}}
|
||||
<script defer src="{{ $mermaidJs.RelPermalink }}" integrity="{{ $mermaidJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else if $mermaidJsAsset -}}
|
||||
{{- with resources.Get $mermaidJsAsset -}}
|
||||
{{- $mermaidJs := . | fingerprint -}}
|
||||
<script defer src="{{ $mermaidJs.RelPermalink }}" integrity="{{ $mermaidJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- else -}}
|
||||
{{- errorf "Mermaid js asset not found at %q" $mermaidJsAsset -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
// Store original mermaid code for each diagram
|
||||
document.querySelectorAll(".mermaid").forEach((el) => {
|
||||
el.dataset.original = el.innerHTML;
|
||||
});
|
||||
|
||||
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
||||
|
||||
let timeout;
|
||||
new MutationObserver(() => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
const theme = document.documentElement.classList.contains("dark") ? "dark" : "default";
|
||||
document.querySelectorAll(".mermaid").forEach((el) => {
|
||||
// Reset to original content, preserving HTML
|
||||
el.innerHTML = el.dataset.original;
|
||||
el.removeAttribute("data-processed");
|
||||
});
|
||||
mermaid.initialize({ startOnLoad: true, theme: theme });
|
||||
mermaid.init();
|
||||
}, 150);
|
||||
}).observe(document.documentElement, {
|
||||
attributes: true,
|
||||
attributeFilter: ["class"],
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,63 @@
|
||||
{{/* Search */}}
|
||||
{{- if (site.Params.search.enable | default true) -}}
|
||||
{{- $searchType := site.Params.search.type | default "flexsearch" -}}
|
||||
{{- if eq $searchType "flexsearch" -}}
|
||||
{{- $jsSearchScript := printf "%s.search.js" .Language.Lang -}}
|
||||
{{- $jsSearch := resources.Get "js/flexsearch.js" | resources.ExecuteAsTemplate $jsSearchScript . -}}
|
||||
{{- if hugo.IsProduction -}}
|
||||
{{- $jsSearch = $jsSearch | minify | fingerprint -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $flexSearchBase := "" -}}
|
||||
{{- $useDefaultCdn := true -}}
|
||||
{{- with site.Params.search.flexsearch.base -}}
|
||||
{{- $flexSearchBase = . -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $flexSearchJsAsset := "" -}}
|
||||
{{- with site.Params.search.flexsearch.js -}}
|
||||
{{- $flexSearchJsAsset = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* If only js is set without base, use local asset loading. */ -}}
|
||||
{{- if and $useDefaultCdn (ne $flexSearchJsAsset "") -}}
|
||||
{{- $useDefaultCdn = false -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $bundleSuffix := cond hugo.IsProduction ".min" ".debug" -}}
|
||||
{{- if $useDefaultCdn -}}
|
||||
{{- $flexSearchVersion := site.Params.search.flexsearch.version | default "0.8.143" -}}
|
||||
{{- $flexSearchBase = printf "https://cdn.jsdelivr.net/npm/flexsearch@%s/dist" $flexSearchVersion -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $isRemoteBase := or (strings.HasPrefix $flexSearchBase "http://") (strings.HasPrefix $flexSearchBase "https://") -}}
|
||||
{{- if $isRemoteBase -}}
|
||||
{{- $jsPath := cond (ne $flexSearchJsAsset "") $flexSearchJsAsset (printf "flexsearch.bundle%s.js" $bundleSuffix) -}}
|
||||
{{- $flexSearchJsUrl := urls.JoinPath $flexSearchBase $jsPath -}}
|
||||
{{- with try (resources.GetRemote $flexSearchJsUrl) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "Could not retrieve FlexSearch js file from %s. Reason: %s." $flexSearchJsUrl . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- with resources.Copy "js/flexsearch.js" . -}}
|
||||
{{- $flexSearchJs := . | fingerprint -}}
|
||||
<script defer src="{{ $flexSearchJs.RelPermalink }}" integrity="{{ $flexSearchJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- else if $flexSearchJsAsset -}}
|
||||
{{- with resources.Get $flexSearchJsAsset -}}
|
||||
{{- $flexSearchJs := . | fingerprint -}}
|
||||
<script defer src="{{ $flexSearchJs.RelPermalink }}" integrity="{{ $flexSearchJs.Data.Integrity }}" crossorigin="anonymous"></script>
|
||||
{{- else -}}
|
||||
{{- errorf "FlexSearch js asset not found at %q" $flexSearchJsAsset -}}
|
||||
{{- end -}}
|
||||
{{- else if not $useDefaultCdn -}}
|
||||
{{- errorf "FlexSearch local loading requires params.search.flexsearch.js when using non-remote base %q" $flexSearchBase -}}
|
||||
{{- end -}}
|
||||
|
||||
<script defer src="{{ $jsSearch.RelPermalink }}" integrity="{{ $jsSearch.Data.Integrity }}"></script>
|
||||
{{- else -}}
|
||||
{{- warnf `search type "%s" is not supported` $searchType -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user