diff --git a/glance-system/glance-kisfenyo.yaml b/glance-system/glance-kisfenyo.yaml index e90325b..5bf9cd1 100644 --- a/glance-system/glance-kisfenyo.yaml +++ b/glance-system/glance-kisfenyo.yaml @@ -125,26 +125,52 @@ data: function indexLinks() { const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json'; - async function loadBookmarksIndex() { - 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(); + let indexLoaded = false; + let indexLoading = null; - // Convert to the format your script already uses - indexed = data.map(x => ({ - title: x.title, - url: x.url, - meta: [x.page, x.widget, x.group].filter(Boolean).join(' • ') - })); - } catch (e) { - console.warn('Could not load bookmarks index, falling back to DOM only:', e); - indexLinksFromDom(); // keep your current DOM indexer as fallback - } + 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: '' + })); } - // call once on load - document.addEventListener('DOMContentLoaded', loadBookmarksIndex); + async function loadBookmarksIndex() { + if (indexLoaded) return; + if (indexLoading) return indexLoading; + + 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 score(item, q) { @@ -170,7 +196,7 @@ data: list().innerHTML = results.map((r, i) => `
${escapeHtml(r.title || r.url)}
-
${escapeHtml(r.url)}
+
${escapeHtml(r.meta || r.url)}
`).join(''); @@ -194,11 +220,15 @@ data: } function openOverlay(withInitialText = '') { - indexLinks(); overlay.style.display = 'flex'; input().value = withInitialText; lastQuery = withInitialText; - const results = render(normalize(withInitialText)); + + // show something instantly + list().innerHTML = `
Loading…
`; + + // then render once index is available + loadBookmarksIndex().then(() => render(normalize(input().value))); input().focus(); function onInput() { @@ -1964,7 +1994,7 @@ spec: fsGroup: 1000 initContainers: - name: build-bookmarks-index - image: ghcr.io/mikefarah/yq:4.44.3 + image: mikefarah/yq:4.50.1 securityContext: runAsUser: 1000 runAsGroup: 1000