we'll see

This commit is contained in:
2026-01-14 20:48:14 +01:00
parent 1c2994c402
commit 4b3779baa7
+17 -19
View File
@@ -118,18 +118,12 @@ data:
let activeIndex = 0; let activeIndex = 0;
let lastQuery = ''; let lastQuery = '';
function normalize(s) {
return (s || '').toLowerCase().replace(/\s+/g, ' ').trim();
}
function indexLinks() {
const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json'; const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json';
let indexLoaded = false; let indexLoaded = false;
let indexLoading = null; let indexLoading = null;
function indexLinksFromDom() { function indexLinksFromDom() {
// fallback: current page bookmarks only
const anchors = document.querySelectorAll('.widget.widget-type-bookmarks a.bookmarks-link[href]'); const anchors = document.querySelectorAll('.widget.widget-type-bookmarks a.bookmarks-link[href]');
indexed = Array.from(anchors).map(a => ({ indexed = Array.from(anchors).map(a => ({
title: (a.textContent || '').trim(), title: (a.textContent || '').trim(),
@@ -138,39 +132,41 @@ data:
})); }));
} }
async function loadBookmarksIndex() { function loadBookmarksIndex() {
if (indexLoaded) return; if (indexLoaded) return Promise.resolve();
if (indexLoading) return indexLoading; if (indexLoading) return indexLoading;
indexLoading = (async () => { indexLoading = fetch(BOOKMARKS_INDEX_URL, { cache: 'no-store' })
try { .then(res => {
const res = await fetch(BOOKMARKS_INDEX_URL, { cache: 'no-store' });
if (!res.ok) throw new Error(`HTTP ${res.status}`); if (!res.ok) throw new Error(`HTTP ${res.status}`);
const data = await res.json(); return res.json();
})
.then(data => {
indexed = data.map(x => ({ indexed = data.map(x => ({
title: x.title, title: x.title,
url: x.url, url: x.url,
meta: [x.page, x.widget, x.group].filter(Boolean).join(' • ') meta: [x.page, x.widget, x.group].filter(Boolean).join(' • ')
})); }));
indexLoaded = true; indexLoaded = true;
} catch (e) { })
.catch(e => {
console.warn('Could not load bookmarks index, falling back to DOM only:', e); console.warn('Could not load bookmarks index, falling back to DOM only:', e);
indexLinksFromDom(); indexLinksFromDom();
indexLoaded = true; indexLoaded = true;
} });
})();
return indexLoading; return indexLoading;
} }
// Load ASAP (works even if DOMContentLoaded already happened) // Load ASAP (works even if DOMContentLoaded already happened)
if (document.readyState === 'loading') { if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadBookmarksIndex); document.addEventListener('DOMContentLoaded', () => loadBookmarksIndex());
} else { } else {
loadBookmarksIndex(); loadBookmarksIndex();
} }
function normalize(s) {
return (s || '').toLowerCase().replace(/\s+/g, ' ').trim();
} }
function score(item, q) { function score(item, q) {
@@ -228,8 +224,10 @@ data:
list().innerHTML = `<div class="gql-item active"><div class="gql-title">Loading…</div></div>`; list().innerHTML = `<div class="gql-item active"><div class="gql-title">Loading…</div></div>`;
// then render once index is available // then render once index is available
loadBookmarksIndex().then(() => render(normalize(input().value))); loadBookmarksIndex().then(() => {
render(normalize(input().value));
input().focus(); input().focus();
});
function onInput() { function onInput() {
lastQuery = input().value; lastQuery = input().value;