we'll see

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