final fixes, hopefully

This commit is contained in:
2026-01-14 20:36:57 +01:00
parent 924bd8434a
commit 1c2994c402
+51 -21
View File
@@ -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) => `
<div class="gql-item ${i===0 ? 'active' : ''}" data-i="${i}">
<div class="gql-title">${escapeHtml(r.title || r.url)}</div>
<div class="gql-url">${escapeHtml(r.url)}</div>
<div class="gql-url">${escapeHtml(r.meta || r.url)}</div>
</div>
`).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 = `<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();
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