Files
hugo-starless/themes/starless/layouts/_default/baseof.html
2026-06-21 16:36:34 +00:00

373 lines
15 KiB
HTML

<!DOCTYPE html>
<html class="dark" lang="{{ site.Language.Locale | default `en` }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="darkreader-lock">
<title>{{ if .IsHome }}{{ site.Title }}{{ else }}{{ .Title }} | {{ site.Title }}{{ end }}</title>
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ site.Params.description }}{{ end }}">
<script src="https://cdn.tailwindcss.com?plugins=forms,container-queries"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,400;0,600;1,400&family=JetBrains+Mono:wght@400;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:wght,FILL@100..700,0..1&display=swap" rel="stylesheet">
{{ if .Params.math }}
<script defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
{{ end }}
<script>
tailwind.config = {
darkMode: "class",
theme: {
extend: {
colors: {
surface: "#161413",
"surface-dim": "#161413",
"surface-bright": "#3d3937",
"surface-container-lowest": "#0c0b0a",
"surface-container-low": "#1d1a19",
"surface-container": "#211e1d",
"surface-container-high": "#2c2826",
"surface-container-highest": "#373130",
"on-surface": "#eae4e2",
"on-surface-variant": "#d2c7c5",
primary: "#d18c81",
"on-primary": "#3e1c15",
"primary-container": "#5b2c23",
"on-primary-container": "#ffdacf",
secondary: "#e2b8b1",
"on-secondary": "#412b26",
"secondary-container": "#5a413b",
"on-secondary-container": "#ffdacf",
tertiary: "#c9c3a3",
"on-tertiary": "#312e18",
"tertiary-container": "#48442c",
"on-tertiary-container": "#e6dfbc",
error: "#ffb4ab",
"on-error": "#690005",
"error-container": "#93000a",
"on-error-container": "#ffdad6",
background: "#161413",
"on-background": "#eae4e2",
outline: "#968d8a",
"outline-variant": "#4d4644",
"inverse-surface": "#eae4e2",
"inverse-on-surface": "#322f2e",
"inverse-primary": "#97483c"
},
borderRadius: {
DEFAULT: "0.25rem",
lg: "0.5rem",
xl: "0.75rem",
full: "9999px"
},
spacing: {
"container-max": "1120px",
"stack-lg": "32px",
"margin-mobile": "16px",
gutter: "24px",
"stack-sm": "4px",
"stack-md": "12px",
base: "8px"
},
fontFamily: {
"body-md": ["JetBrains Mono", "monospace"],
"body-lg": ["JetBrains Mono", "monospace"],
"display-lg": ["Cormorant Garamond", "serif"],
"headline-md": ["Cormorant Garamond", "serif"],
"label-sm": ["JetBrains Mono", "monospace"],
"display-lg-mobile": ["Cormorant Garamond", "serif"]
},
fontSize: {
"body-md": ["14px", { lineHeight: "24px", fontWeight: "400" }],
"body-lg": ["16px", { lineHeight: "28px", fontWeight: "400" }],
"display-lg": ["42px", { lineHeight: "1.2", fontWeight: "400" }],
"headline-md": ["24px", { lineHeight: "32px", fontWeight: "400" }],
"label-sm": ["12px", { lineHeight: "16px", fontWeight: "400" }],
"display-lg-mobile": ["32px", { lineHeight: "40px", fontWeight: "400" }]
}
}
}
}
</script>
<style>
.material-symbols-outlined {
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}
[hidden] {
display: none !important;
}
.tree-item {
position: relative;
}
.tree-item::before {
content: '';
position: absolute;
left: -12px;
top: 0;
bottom: 0;
width: 1px;
background-color: rgba(234, 228, 226, 0.1);
}
#search-dialog {
margin-top: 6rem;
}
#search-dialog::backdrop {
background: rgba(12, 11, 10, 0.86);
}
.highlight pre {
padding: 0.5rem 1rem;
}
@media (max-width: 768px) {
#search-dialog {
margin-top: 1rem;
}
}
</style>
</head>
<body class="bg-surface text-on-surface font-body-md min-h-screen flex antialiased">
<div class="flex w-full max-w-7xl mx-auto px-8 py-16 gap-16">
{{ partial "sidebar.html" . }}
<main class="flex-1 max-w-3xl pt-2">
{{ block "main" . }}{{ end }}
</main>
</div>
<dialog id="search-dialog" class="w-[min(78rem,calc(100vw-2rem))] max-w-none bg-transparent p-0 text-on-surface backdrop:bg-surface/90">
<div class="flex flex-col gap-4">
<div class="relative">
<span class="material-symbols-outlined absolute left-3 top-2.5 text-on-surface-variant text-[20px]" aria-hidden="true">search</span>
<input id="search-input" class="w-full bg-surface-container-lowest/95 text-on-surface border border-outline/30 rounded py-2.5 pl-10 pr-12 focus:outline-none focus:border-primary focus:ring-1 focus:ring-primary transition-colors placeholder-on-surface-variant/60 text-body-md" type="text" placeholder="Search" autocomplete="off" spellcheck="false" aria-label="Search">
<button class="absolute right-2 top-2 inline-flex h-7 w-7 items-center justify-center rounded text-on-surface-variant hover:text-on-surface focus:outline-none focus:ring-1 focus:ring-primary" type="button" data-search-close aria-label="Close search">
<span class="material-symbols-outlined text-[18px]" aria-hidden="true">close</span>
</button>
</div>
<div class="grid min-h-[28rem] max-h-[70vh] overflow-hidden rounded border border-outline/30 bg-surface-container-lowest/95 md:grid-cols-[minmax(14rem,24rem)_1fr]" data-search-panel hidden>
<div class="overflow-y-auto border-b border-outline/30 md:border-b-0 md:border-r" data-search-results></div>
<article class="overflow-y-auto p-6 md:p-8" data-search-preview>
<p class="text-on-surface-variant">Search</p>
</article>
<div class="flex min-h-[28rem] items-center justify-center p-6 text-center text-on-surface-variant md:col-span-2" data-search-message hidden></div>
</div>
</div>
</dialog>
<script>
(() => {
const dialog = document.getElementById("search-dialog");
const input = document.getElementById("search-input");
const panelEl = dialog.querySelector("[data-search-panel]");
const resultsEl = dialog.querySelector("[data-search-results]");
const previewEl = dialog.querySelector("[data-search-preview]");
const messageEl = dialog.querySelector("[data-search-message]");
const openButtons = document.querySelectorAll("[data-search-open]");
const closeButton = dialog.querySelector("[data-search-close]");
const indexUrl = "{{ "index.json" | relURL }}";
const flexSearchUrl = "{{ "js/flexsearch.bundle.min.js" | relURL }}";
const resultLimit = 10;
let searchIndex;
let ready;
let timer;
const loadScript = (src) => new Promise((resolve, reject) => {
if (window.FlexSearch) {
resolve();
return;
}
const existing = document.querySelector(`script[src="${src}"]`);
if (existing) {
existing.addEventListener("load", resolve, { once: true });
existing.addEventListener("error", reject, { once: true });
return;
}
const script = document.createElement("script");
script.src = src;
script.async = true;
script.onload = resolve;
script.onerror = reject;
document.head.appendChild(script);
});
const setup = () => {
if (ready) return ready;
ready = Promise.all([
loadScript(flexSearchUrl),
fetch(indexUrl).then((response) => {
if (!response.ok) throw new Error("Search index failed to load");
return response.json();
})
]).then(([, docs]) => {
searchIndex = new window.FlexSearch.Document({
tokenize: "forward",
document: {
id: "id",
index: ["title", "summary", "content"],
store: ["id", "title", "url", "summary", "content"]
}
});
docs.forEach((doc) => searchIndex.add(doc));
});
return ready;
};
const hidePanel = () => {
panelEl.hidden = true;
resultsEl.hidden = false;
previewEl.hidden = false;
messageEl.hidden = true;
resultsEl.replaceChildren();
previewEl.replaceChildren();
messageEl.textContent = "";
};
const showMessage = (message) => {
panelEl.hidden = false;
resultsEl.hidden = true;
previewEl.hidden = true;
messageEl.hidden = false;
messageEl.textContent = message;
};
const showResultsPanel = () => {
panelEl.hidden = false;
resultsEl.hidden = false;
previewEl.hidden = false;
messageEl.hidden = true;
messageEl.textContent = "";
};
const snippet = (text, query) => {
const clean = (text || "").replace(/\s+/g, " ").trim();
if (!clean) return "";
const lower = clean.toLowerCase();
const needle = query.toLowerCase().split(/\s+/).find(Boolean) || query.toLowerCase();
const hit = lower.indexOf(needle);
const start = Math.max(0, hit - 140);
const end = Math.min(clean.length, start + 720);
return `${start ? "... " : ""}${clean.slice(start, end)}${end < clean.length ? " ..." : ""}`;
};
const highlight = (node, text, query) => {
const terms = query
.trim()
.split(/\s+/)
.filter(Boolean)
.sort((a, b) => b.length - a.length)
.map((term) => term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
const pattern = terms.length && new RegExp(`(${terms.join("|")})`, "gi");
node.replaceChildren();
if (!pattern) {
node.textContent = text || "";
return;
}
String(text || "").split(pattern).forEach((part) => {
if (!part) return;
if (pattern.test(part)) {
const mark = document.createElement("mark");
mark.className = "rounded bg-primary-container px-0.5 text-on-primary-container";
mark.textContent = part;
node.appendChild(mark);
} else {
node.appendChild(document.createTextNode(part));
}
pattern.lastIndex = 0;
});
};
const showPreview = (doc, query) => {
previewEl.replaceChildren();
const title = document.createElement("a");
title.className = "block font-display-lg text-headline-md text-on-surface hover:text-primary transition-colors";
title.href = doc.url;
highlight(title, doc.title, query);
const summary = document.createElement("p");
summary.className = "mt-4 text-on-surface/90";
highlight(summary, doc.summary || "", query);
const body = document.createElement("p");
body.className = "mt-6 whitespace-pre-wrap text-on-surface-variant";
highlight(body, snippet(doc.content, query), query);
previewEl.append(title, summary, body);
};
const flattenResults = (groups) => {
const seen = new Map();
groups.forEach((group) => {
const weight = group.field === "title" ? 0 : group.field === "summary" ? 1 : 2;
group.result.forEach((item, offset) => {
const doc = item.doc;
const current = doc && seen.get(item.id);
if (!doc || (current && current.weight <= weight)) return;
seen.set(item.id, { doc, weight, offset });
});
});
return Array.from(seen.values())
.sort((a, b) => a.weight - b.weight || a.offset - b.offset)
.slice(0, resultLimit)
.map((item) => item.doc);
};
const runSearch = () => {
const query = input.value.trim();
if (!query) {
hidePanel();
return;
}
const matches = flattenResults(searchIndex.search(query, { enrich: true, limit: resultLimit }));
resultsEl.replaceChildren();
if (!matches.length) {
showMessage("No results");
return;
}
showResultsPanel();
matches.forEach((doc, index) => {
const link = document.createElement("a");
link.className = "block border-b border-outline/30 px-4 py-3 text-on-surface hover:bg-surface-container-low focus:bg-surface-container-low focus:outline-none";
link.href = doc.url;
link.textContent = doc.title;
link.addEventListener("mouseenter", () => showPreview(doc, query));
link.addEventListener("focus", () => showPreview(doc, query));
resultsEl.appendChild(link);
if (index === 0) showPreview(doc, query);
});
};
const queueSearch = () => {
clearTimeout(timer);
timer = setTimeout(() => {
setup().then(runSearch).catch(() => showMessage("Search unavailable"));
}, 120);
};
openButtons.forEach((button) => {
button.addEventListener("click", () => {
if (!dialog.open) dialog.showModal();
requestAnimationFrame(() => input.focus());
setup().then(runSearch).catch(() => showMessage("Search unavailable"));
});
});
const resetSearch = () => {
input.value = "";
hidePanel();
};
closeButton.addEventListener("click", () => dialog.close());
dialog.addEventListener("close", resetSearch);
dialog.addEventListener("click", (event) => {
if (event.target === dialog) dialog.close();
});
input.addEventListener("input", queueSearch);
})();
</script>
</body>
</html>