mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2025-01-09 16:39:51 +01:00
Merge 781385f991
into 48829f9d5b
This commit is contained in:
commit
ed3ec2c1e6
4 changed files with 77 additions and 2 deletions
|
@ -14,7 +14,7 @@ indent_style = space
|
|||
indent_size = 2
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{nix,yml,yaml}]
|
||||
[*.{js,nix,yml,yaml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
tab_width = 2
|
||||
|
|
|
@ -62,7 +62,8 @@ in
|
|||
# Copy anchor scripts to the script directory in document root.
|
||||
cp -vt "$dest"/script \
|
||||
${./static/script}/anchor-min.js \
|
||||
${./static/script}/anchor-use.js
|
||||
${./static/script}/anchor-use.js \
|
||||
${./static/script}/search.js
|
||||
|
||||
substituteInPlace ./options.md \
|
||||
--subst-var-by OPTIONS_JSON ./config-options.json
|
||||
|
@ -100,6 +101,7 @@ in
|
|||
--script highlightjs/loader.js \
|
||||
--script script/anchor-use.js \
|
||||
--script script/anchor-min.js \
|
||||
--script script/search.js \
|
||||
--toc-depth 2 \
|
||||
--section-toc-depth 1 \
|
||||
manual.md \
|
||||
|
|
47
docs/static/script/search.js
vendored
Normal file
47
docs/static/script/search.js
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
document.addEventListener("DOMContentLoaded", () => {
|
||||
if (!window.location.pathname.endsWith("options.html")) return;
|
||||
|
||||
const searchDiv = document.createElement("div");
|
||||
searchDiv.id = "search-bar";
|
||||
searchDiv.innerHTML = `
|
||||
<input type="text" id="search-input" placeholder="Search options by ID..." />
|
||||
<div id="search-results"></div>
|
||||
`;
|
||||
document.body.prepend(searchDiv);
|
||||
|
||||
const dtElements = Array.from(document.querySelectorAll("dt"));
|
||||
const ddElements = Array.from(document.querySelectorAll("dd"));
|
||||
const dtOptionIds = dtElements.map(
|
||||
(dt) => dt.querySelector("a")?.id.toLowerCase() || "",
|
||||
);
|
||||
|
||||
if (dtElements.length === 0 || ddElements.length === 0) {
|
||||
console.warn("Something went wrong, page may be loaded incorrectly.");
|
||||
return;
|
||||
}
|
||||
|
||||
const dtElementsData = dtElements.map((dt, index) => ({
|
||||
element: dt,
|
||||
id: dtOptionIds[index],
|
||||
ddElement: ddElements[index],
|
||||
}));
|
||||
|
||||
let debounceTimeout;
|
||||
document.getElementById("search-input").addEventListener("input", (event) => {
|
||||
clearTimeout(debounceTimeout);
|
||||
debounceTimeout = setTimeout(() => {
|
||||
const query = event.target.value.toLowerCase();
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
const fragment = document.createDocumentFragment();
|
||||
dtElementsData.forEach(({ element, id, ddElement }) => {
|
||||
const isMatch = id.includes(query);
|
||||
if (element.classList.contains("hidden") !== !isMatch) {
|
||||
element.classList.toggle("hidden", !isMatch);
|
||||
ddElement?.classList.toggle("hidden", !isMatch);
|
||||
}
|
||||
});
|
||||
});
|
||||
}, 200);
|
||||
});
|
||||
});
|
26
docs/static/style.scss
vendored
26
docs/static/style.scss
vendored
|
@ -233,6 +233,32 @@ li {
|
|||
}
|
||||
}
|
||||
|
||||
#search-bar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
background: white;
|
||||
padding: 10px;
|
||||
border-bottom: 1px solid #ccc;
|
||||
z-index: 1000;
|
||||
@media (prefers-color-scheme: dark) {
|
||||
background: $color-gray-900;
|
||||
color: $color-gray-50;
|
||||
}
|
||||
}
|
||||
|
||||
#search-input {
|
||||
width: 100%;
|
||||
padding: 8px;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 4px;
|
||||
background: inherit;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
div.titlepage {
|
||||
margin: 40px 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue