final fixes, hopefully
This commit is contained in:
@@ -125,26 +125,52 @@ data:
|
|||||||
function indexLinks() {
|
function indexLinks() {
|
||||||
const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json';
|
const BOOKMARKS_INDEX_URL = '/assets/bookmarks.json';
|
||||||
|
|
||||||
|
let indexLoaded = false;
|
||||||
|
let indexLoading = null;
|
||||||
|
|
||||||
|
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: ''
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
async function loadBookmarksIndex() {
|
async function loadBookmarksIndex() {
|
||||||
|
if (indexLoaded) return;
|
||||||
|
if (indexLoading) return indexLoading;
|
||||||
|
|
||||||
|
indexLoading = (async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch(BOOKMARKS_INDEX_URL, { cache: 'no-store' });
|
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();
|
const data = await res.json();
|
||||||
|
|
||||||
// Convert to the format your script already uses
|
|
||||||
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;
|
||||||
} 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(); // keep your current DOM indexer as fallback
|
indexLinksFromDom();
|
||||||
|
indexLoaded = true;
|
||||||
}
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
return indexLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
// call once on load
|
// Load ASAP (works even if DOMContentLoaded already happened)
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', loadBookmarksIndex);
|
document.addEventListener('DOMContentLoaded', loadBookmarksIndex);
|
||||||
|
} else {
|
||||||
|
loadBookmarksIndex();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function score(item, q) {
|
function score(item, q) {
|
||||||
@@ -170,7 +196,7 @@ data:
|
|||||||
list().innerHTML = results.map((r, i) => `
|
list().innerHTML = results.map((r, i) => `
|
||||||
<div class="gql-item ${i===0 ? 'active' : ''}" data-i="${i}">
|
<div class="gql-item ${i===0 ? 'active' : ''}" data-i="${i}">
|
||||||
<div class="gql-title">${escapeHtml(r.title || r.url)}</div>
|
<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>
|
</div>
|
||||||
`).join('');
|
`).join('');
|
||||||
|
|
||||||
@@ -194,11 +220,15 @@ data:
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openOverlay(withInitialText = '') {
|
function openOverlay(withInitialText = '') {
|
||||||
indexLinks();
|
|
||||||
overlay.style.display = 'flex';
|
overlay.style.display = 'flex';
|
||||||
input().value = withInitialText;
|
input().value = withInitialText;
|
||||||
lastQuery = 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();
|
input().focus();
|
||||||
|
|
||||||
function onInput() {
|
function onInput() {
|
||||||
@@ -1964,7 +1994,7 @@ spec:
|
|||||||
fsGroup: 1000
|
fsGroup: 1000
|
||||||
initContainers:
|
initContainers:
|
||||||
- name: build-bookmarks-index
|
- name: build-bookmarks-index
|
||||||
image: ghcr.io/mikefarah/yq:4.44.3
|
image: mikefarah/yq:4.50.1
|
||||||
securityContext:
|
securityContext:
|
||||||
runAsUser: 1000
|
runAsUser: 1000
|
||||||
runAsGroup: 1000
|
runAsGroup: 1000
|
||||||
|
|||||||
Reference in New Issue
Block a user