Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Rebuild the docs as a MkDocs site

1f8afe73515d58c14774878f30f33bfe318d0c3b · Keenan Nemetz · 21d ago · parent 7c02af12

Rebuild the docs as a MkDocs site

Replace the mdBook configuration with MkDocs and a local theme that uses
Vole's Everforest dark/medium palette. Move the contents order into nav,
make docs/index.md the homepage, and carry the install, quickstart,
deployment, and reference pages into the new tree.

Add the docs build to verify, with pinned requirements and python3-venv in
the image, so a broken nav entry or theme asset fails before a pages
deploy.

docs-theme/assets/docs.js +235

@@ -0,0 +1,235 @@
1 /* The docs have two pieces of behaviour: a small-screen navigation drawer and
2 the search palette. Both are progressive: without this script the links and
3 page content still work, and the search button simply does nothing. */
4 (() => {
5 const body = document.body;
6
7 /* ---------- navigation drawer ---------- */
8
9 const navToggle = document.querySelector('[data-nav-toggle]');
10 const setNav = (open) => {
11 body.classList.toggle('nav-open', open);
12 if (navToggle) navToggle.setAttribute('aria-expanded', String(open));
13 };
14
15 if (navToggle) {
16 navToggle.addEventListener('click', () => {
17 setNav(!body.classList.contains('nav-open'));
18 });
19 }
20 document.querySelectorAll('[data-nav-close]').forEach((element) => {
21 element.addEventListener('click', () => setNav(false));
22 });
23 document.querySelectorAll('.sidebar a').forEach((link) => {
24 link.addEventListener('click', () => setNav(false));
25 });
26
27 /* ---------- copy buttons ---------- */
28
29 document.querySelectorAll('.content .codehilite').forEach((block) => {
30 const button = document.createElement('button');
31 button.type = 'button';
32 button.className = 'copy-code';
33 button.textContent = 'Copy';
34 button.setAttribute('aria-label', 'Copy code');
35 button.addEventListener('click', async () => {
36 const code = block.querySelector('code');
37 if (!code) return;
38 try {
39 await navigator.clipboard.writeText(code.textContent);
40 button.textContent = 'Copied';
41 } catch (err) {
42 button.textContent = 'Copy failed';
43 }
44 window.setTimeout(() => { button.textContent = 'Copy'; }, 1400);
45 });
46 block.append(button);
47 });
48
49 /* ---------- search palette ---------- */
50
51 const dialog = document.getElementById('search-palette');
52 const input = document.getElementById('search-query');
53 const results = document.getElementById('search-results');
54 const openers = document.querySelectorAll('[data-search-open]');
55 if (!dialog || !input || !results) return;
56
57 const root = new URL(window.DOCS_BASE_URL || './', window.location.href);
58 const rootUrl = (path) => new URL(path, root).href;
59 const empty = (message) => {
60 results.replaceChildren();
61 const p = document.createElement('p');
62 p.className = 'palette-empty';
63 p.textContent = message;
64 results.append(p);
65 };
66
67 let worker = null;
68 let ready = false;
69 let minLength = 2;
70 let selected = -1;
71 let timer = 0;
72 let returnFocus = null;
73
74 const select = (index) => {
75 const rows = results.querySelectorAll('.palette-row');
76 if (!rows.length) return;
77 selected = (index + rows.length) % rows.length;
78 rows.forEach((row, i) => {
79 const on = i === selected;
80 row.classList.toggle('is-selected', on);
81 row.setAttribute('aria-selected', String(on));
82 });
83 rows[selected].scrollIntoView({ block: 'nearest' });
84 };
85
86 const render = (items) => {
87 results.replaceChildren();
88 selected = -1;
89 if (!items.length) {
90 empty('No results found.');
91 return;
92 }
93 items.forEach((item) => {
94 const row = document.createElement('a');
95 row.className = 'palette-row';
96 row.href = rootUrl(item.location);
97 row.setAttribute('role', 'option');
98
99 const title = document.createElement('span');
100 title.className = 'palette-row-title';
101 title.textContent = item.title || item.location;
102
103 const where = document.createElement('span');
104 where.className = 'palette-row-where';
105 where.textContent = item.summary || item.location;
106
107 row.append(title, where);
108 row.addEventListener('mouseenter', () => {
109 const rows = [...results.querySelectorAll('.palette-row')];
110 select(rows.indexOf(row));
111 });
112 results.append(row);
113 });
114 };
115
116 const search = () => {
117 const query = input.value.trim();
118 if (!query) {
119 empty('Type to search the documentation.');
120 return;
121 }
122 if (!ready) {
123 empty('Search is still loading…');
124 return;
125 }
126 if (query.length < minLength) {
127 empty(`Type at least ${minLength} characters.`);
128 return;
129 }
130 worker.postMessage({ query });
131 };
132
133 const openSearch = () => {
134 if (dialog.open) return;
135 returnFocus = document.activeElement;
136 if (typeof dialog.showModal === 'function') {
137 dialog.showModal();
138 } else {
139 dialog.setAttribute('open', '');
140 }
141 input.focus();
142 input.select();
143 search();
144 };
145
146 const closeSearch = () => {
147 if (typeof dialog.close === 'function') {
148 dialog.close();
149 } else {
150 dialog.removeAttribute('open');
151 }
152 if (returnFocus && typeof returnFocus.focus === 'function') returnFocus.focus();
153 };
154
155 openers.forEach((button) => button.addEventListener('click', openSearch));
156 document.querySelectorAll('[data-search-close]').forEach((button) => {
157 button.addEventListener('click', closeSearch);
158 });
159
160 // A click on the dialog itself is a click on the backdrop; clicks on the form
161 // and result rows have a deeper target.
162 dialog.addEventListener('click', (event) => {
163 if (event.target === dialog) closeSearch();
164 });
165
166 input.addEventListener('input', () => {
167 window.clearTimeout(timer);
168 timer = window.setTimeout(search, 140);
169 });
170
171 const form = dialog.querySelector('[data-search-form]');
172 if (form) {
173 form.addEventListener('submit', (event) => {
174 event.preventDefault();
175 const selectedRow = results.querySelector('.palette-row.is-selected');
176 if (selectedRow) {
177 window.location.href = selectedRow.href;
178 } else {
179 search();
180 }
181 });
182 }
183
184 input.addEventListener('keydown', (event) => {
185 if (event.key === 'ArrowDown') {
186 event.preventDefault();
187 select(selected + 1);
188 } else if (event.key === 'ArrowUp') {
189 event.preventDefault();
190 select(selected - 1);
191 } else if (event.key === 'Enter' && selected >= 0) {
192 event.preventDefault();
193 const selectedRow = results.querySelectorAll('.palette-row')[selected];
194 if (selectedRow) window.location.href = selectedRow.href;
195 }
196 });
197
198 document.addEventListener('keydown', (event) => {
199 const target = event.target;
200 const tag = (target && target.tagName ? target.tagName : '').toLowerCase();
201 const typing = tag === 'input' || tag === 'textarea' || tag === 'select' || (target && target.isContentEditable);
202 const slash = event.key === '/' && !typing && !event.metaKey && !event.ctrlKey && !event.altKey;
203 const commandK = (event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'k';
204 if (slash || commandK) {
205 event.preventDefault();
206 openSearch();
207 return;
208 }
209 if (event.key === 'Escape' && body.classList.contains('nav-open')) {
210 setNav(false);
211 }
212 });
213
214 if (!window.Worker) {
215 empty('Search needs a browser with Web Workers.');
216 return;
217 }
218
219 try {
220 worker = new Worker(rootUrl('search/worker.js'));
221 } catch (err) {
222 empty('Search is unavailable in this browser.');
223 return;
224 }
225 worker.addEventListener('message', (event) => {
226 const data = event.data;
227 if (data.config) minLength = data.config.min_search_length || minLength;
228 if (data.allowSearch) {
229 ready = true;
230 if (dialog.open) search();
231 }
232 if (data.results) render(data.results);
233 });
234 worker.postMessage({ init: true });
235 })();