|
11 | 11 | // |
12 | 12 | // Single file, no build, no framework. Local pane contract (ES module): |
13 | 13 | // export default { canHandle(node, h) -> boolean, render(node, h) -> htmlString } |
14 | | -// where h = { escape, prop, propAll, idOf, types, host, fmtDate, localName }. |
| 14 | +// where h = { escape, prop, propAll, first, idOf, types, host, fmtDate, localName }. |
| 15 | +// (prop may return an array for multi-valued JSON-LD; use h.first for single values.) |
15 | 16 |
|
16 | 17 | document.head.insertAdjacentHTML('beforeend', `<style> |
17 | 18 | body{font:14px/1.55 system-ui,-apple-system,sans-serif;margin:0;color:#222;background:#f3eee5} |
@@ -86,7 +87,7 @@ body{font:14px/1.55 system-ui,-apple-system,sans-serif;margin:0;color:#222;backg |
86 | 87 | async function renderLocalPane(node) { |
87 | 88 | const panes = await loadLocalPanes(); |
88 | 89 | if (!panes.length) return null; |
89 | | - const h = { escape, prop, propAll, idOf, types: typesOf, host: hostOf, fmtDate: fmtDay, localName: localType }; |
| 90 | + const h = { escape, prop, propAll, first: firstVal, idOf, types: typesOf, host: hostOf, fmtDate: fmtDay, localName: localType }; |
90 | 91 | for (const p of panes) { |
91 | 92 | try { if (p.canHandle(node, h)) return p.render(node, h); } catch (e) { /* skip */ } |
92 | 93 | } |
@@ -135,7 +136,9 @@ body{font:14px/1.55 system-ui,-apple-system,sans-serif;margin:0;color:#222;backg |
135 | 136 | return undefined; |
136 | 137 | } |
137 | 138 | function propAll(node, key) { const v = prop(node, key); return v == null ? [] : (Array.isArray(v) ? v : [v]); } |
138 | | - function idOf(v) { return v == null ? '' : (typeof v === 'string' ? v : (v['@id'] || v.id || '')); } |
| 139 | + // First value of a possibly-multi-valued JSON-LD property. |
| 140 | + function firstVal(v) { return Array.isArray(v) ? v[0] : v; } |
| 141 | + function idOf(v) { if (Array.isArray(v)) v = v[0]; return v == null ? '' : (typeof v === 'string' ? v : (v['@id'] || v.id || '')); } |
139 | 142 | function hostOf(u) { try { return new URL(u).host; } catch (e) { return u; } } |
140 | 143 | function fmtDay(iso) { |
141 | 144 | if (!iso) return ''; |
|
0 commit comments