Spaces:
Running
Running
landing: Contents tree — full topic hierarchy with rollup word + reference counts at each level (root total, per-category rollup, per-article), collapsible; replaces the flat map
Browse files- app.js +64 -16
- styles.css +42 -25
app.js
CHANGED
|
@@ -24,6 +24,7 @@ const state = {
|
|
| 24 |
taxonomy: null, // parsed taxonomy.yaml { cat: {description, nodes:{slug:scope}} }
|
| 25 |
tax: [], // ordered [{cat, description, nodes:[{slug,scope,page}], written, total}]
|
| 26 |
collapsed: new Set(JSON.parse(localStorage.getItem('viz-collapsed') || '[]')),
|
|
|
|
| 27 |
srcNs: null, // selected source-namespace filter (null = all)
|
| 28 |
palItems: [], // command-palette index
|
| 29 |
palFiltered: [],
|
|
@@ -31,6 +32,8 @@ const state = {
|
|
| 31 |
pageContent: new Map(), // path -> article markdown (cached)
|
| 32 |
citedBy: new Map(), // sourceId -> Set(topic path) that cite it
|
| 33 |
citeCount: new Map(), // sourceId -> # distinct articles citing it
|
|
|
|
|
|
|
| 34 |
citemapStarted: false,
|
| 35 |
citemapReady: false,
|
| 36 |
sourcesLoaded: false, // ids known (tree/cache/api) → citations resolve
|
|
@@ -497,27 +500,53 @@ function renderHome() {
|
|
| 497 |
html += `</div>`;
|
| 498 |
}
|
| 499 |
|
| 500 |
-
//
|
| 501 |
-
html += `<div class="section-head">
|
| 502 |
-
<p class="section-lead">
|
| 503 |
if (!state.tax.length) {
|
| 504 |
html += `<div class="nav-empty">No topics yet — the wiki is just getting started.</div>`;
|
| 505 |
} else {
|
| 506 |
-
|
|
|
|
|
|
|
|
|
|
| 507 |
const written = c.nodes.filter(n => n.page);
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 518 |
</div>
|
| 519 |
</div>`;
|
| 520 |
});
|
|
|
|
| 521 |
}
|
| 522 |
|
| 523 |
// The most load-bearing sources — a compact "further reading" once the map is built.
|
|
@@ -547,6 +576,14 @@ function renderHome() {
|
|
| 547 |
|
| 548 |
$$('#view [data-go]').forEach(n => n.addEventListener('click', () => go(n.getAttribute('data-go'))));
|
| 549 |
$$('#view [data-ext]').forEach(n => n.addEventListener('click', () => window.open(n.getAttribute('data-ext'), '_blank')));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
}
|
| 551 |
|
| 552 |
/* ── TOPIC ARTICLE ─────────────────────────────────────── */
|
|
@@ -1166,9 +1203,11 @@ async function ensureCitemap() {
|
|
| 1166 |
try {
|
| 1167 |
const content = await getPageContent(path);
|
| 1168 |
const ids = new Set();
|
| 1169 |
-
const re = /\[source:([^\]\s]+)\]/g; let m;
|
| 1170 |
-
while ((m = re.exec(content))) ids.add(m[1]);
|
| 1171 |
ids.forEach(id => { if (!state.citedBy.has(id)) state.citedBy.set(id, new Set()); state.citedBy.get(id).add(path); });
|
|
|
|
|
|
|
| 1172 |
} catch (e) { /* skip unreadable article */ }
|
| 1173 |
}
|
| 1174 |
};
|
|
@@ -1180,6 +1219,15 @@ async function ensureCitemap() {
|
|
| 1180 |
state.citemapReady = true;
|
| 1181 |
refreshCitationViews();
|
| 1182 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1183 |
// Re-render whatever's on screen that depends on citation data, now that it's ready.
|
| 1184 |
function refreshCitationViews() {
|
| 1185 |
const r = parseHash();
|
|
|
|
| 24 |
taxonomy: null, // parsed taxonomy.yaml { cat: {description, nodes:{slug:scope}} }
|
| 25 |
tax: [], // ordered [{cat, description, nodes:[{slug,scope,page}], written, total}]
|
| 26 |
collapsed: new Set(JSON.parse(localStorage.getItem('viz-collapsed') || '[]')),
|
| 27 |
+
treeCollapsed: new Set(JSON.parse(localStorage.getItem('viz-tree-collapsed') || '[]')),
|
| 28 |
srcNs: null, // selected source-namespace filter (null = all)
|
| 29 |
palItems: [], // command-palette index
|
| 30 |
palFiltered: [],
|
|
|
|
| 32 |
pageContent: new Map(), // path -> article markdown (cached)
|
| 33 |
citedBy: new Map(), // sourceId -> Set(topic path) that cite it
|
| 34 |
citeCount: new Map(), // sourceId -> # distinct articles citing it
|
| 35 |
+
wordCount: new Map(), // topic path -> prose word count
|
| 36 |
+
refCount: new Map(), // topic path -> # inline [source:] citations
|
| 37 |
citemapStarted: false,
|
| 38 |
citemapReady: false,
|
| 39 |
sourcesLoaded: false, // ids known (tree/cache/api) → citations resolve
|
|
|
|
| 500 |
html += `</div>`;
|
| 501 |
}
|
| 502 |
|
| 503 |
+
// Contents — the full topic tree with rollup depth metrics (words + references).
|
| 504 |
+
html += `<div class="section-head">Contents</div>
|
| 505 |
+
<p class="section-lead">The full topic tree. Each level totals the <b>words</b> and <b>references</b> (inline citations) it holds — itself and everything below — a rough gauge of depth. <span class="tl-dot"></span> written · <span class="tl-dot planned"></span> planned.</p>`;
|
| 506 |
if (!state.tax.length) {
|
| 507 |
html += `<div class="nav-empty">No topics yet — the wiki is just getting started.</div>`;
|
| 508 |
} else {
|
| 509 |
+
const ready = state.citemapReady;
|
| 510 |
+
// rollups per category + root
|
| 511 |
+
let rootW = 0, rootR = 0, rootA = 0;
|
| 512 |
+
const cats = state.tax.map(c => {
|
| 513 |
const written = c.nodes.filter(n => n.page);
|
| 514 |
+
let w = 0, r = 0;
|
| 515 |
+
written.forEach(n => { w += state.wordCount.get(n.page.path) || 0; r += state.refCount.get(n.page.path) || 0; });
|
| 516 |
+
rootW += w; rootR += r; rootA += written.length;
|
| 517 |
+
return { c, written, w, r };
|
| 518 |
+
});
|
| 519 |
+
const rollup = (w, r) => ready ? `<span class="t-count"><b>${fmtNum(w)}</b> words · <b>${fmtNum(r)}</b> refs</span>` : '';
|
| 520 |
+
html += `<div class="tree">`;
|
| 521 |
+
html += `<div class="tree-root">${ready
|
| 522 |
+
? `<b>${fmtNum(rootW)}</b> words · <b>${fmtNum(rootR)}</b> references · <b>${rootA}</b> articles across ${state.tax.length} categories`
|
| 523 |
+
: `<span class="mini-spin"></span> measuring depth across ${state.pages.length} articles…`}</div>`;
|
| 524 |
+
cats.forEach(({ c, written, w, r }) => {
|
| 525 |
+
const collapsed = state.treeCollapsed.has(c.cat);
|
| 526 |
+
const planned = c.nodes.filter(n => !n.page);
|
| 527 |
+
const shownPlanned = planned.slice(0, MAP_PLANNED_CAP);
|
| 528 |
+
html += `<div class="tree-cat">
|
| 529 |
+
<button class="tree-cat-head${collapsed ? ' collapsed' : ''}" data-tcat="${esc(c.cat)}">
|
| 530 |
+
<span class="caret">▾</span>
|
| 531 |
+
<span class="tc-name">${esc(catDisplay(c.cat))}</span>
|
| 532 |
+
<span class="tc-frac"><b class="w">${c.written}</b>/${c.total}</span>
|
| 533 |
+
${rollup(w, r)}
|
| 534 |
+
</button>
|
| 535 |
+
<div class="tree-cat-body${collapsed ? ' collapsed' : ''}">
|
| 536 |
+
${c.description ? `<div class="tree-desc">${esc(c.description)}</div>` : ''}
|
| 537 |
+
${written.map(n => {
|
| 538 |
+
const pw = state.wordCount.get(n.page.path) || 0, pr = state.refCount.get(n.page.path) || 0;
|
| 539 |
+
return `<a class="tree-leaf" href="#/topic/${encodeURIComponent(n.page.path)}">
|
| 540 |
+
<span class="tl-dot"></span><span class="tl-name">${esc(n.page.title || n.slug)}</span>
|
| 541 |
+
${ready ? `<span class="t-count">${fmtNum(pw)} words · ${pr} refs</span>` : ''}</a>`;
|
| 542 |
+
}).join('')}
|
| 543 |
+
${shownPlanned.map(n => `<span class="tree-leaf planned" ${n.scope ? `title="${esc(n.scope)}"` : ''}>
|
| 544 |
+
<span class="tl-dot planned"></span><span class="tl-name">${esc(catDisplay(n.slug))}</span><span class="tl-tag">planned</span></span>`).join('')}
|
| 545 |
+
${planned.length > shownPlanned.length ? `<span class="tree-leaf planned"><span class="tl-dot planned"></span><span class="tl-name">+${planned.length - shownPlanned.length} more planned</span></span>` : ''}
|
| 546 |
</div>
|
| 547 |
</div>`;
|
| 548 |
});
|
| 549 |
+
html += `</div>`;
|
| 550 |
}
|
| 551 |
|
| 552 |
// The most load-bearing sources — a compact "further reading" once the map is built.
|
|
|
|
| 576 |
|
| 577 |
$$('#view [data-go]').forEach(n => n.addEventListener('click', () => go(n.getAttribute('data-go'))));
|
| 578 |
$$('#view [data-ext]').forEach(n => n.addEventListener('click', () => window.open(n.getAttribute('data-ext'), '_blank')));
|
| 579 |
+
$$('#view [data-tcat]').forEach(n => n.addEventListener('click', () => toggleTreeCat(n.getAttribute('data-tcat'))));
|
| 580 |
+
}
|
| 581 |
+
// Collapse/expand a category in the Contents tree, without a full re-render (preserves scroll).
|
| 582 |
+
function toggleTreeCat(cat) {
|
| 583 |
+
if (state.treeCollapsed.has(cat)) state.treeCollapsed.delete(cat); else state.treeCollapsed.add(cat);
|
| 584 |
+
localStorage.setItem('viz-tree-collapsed', JSON.stringify([...state.treeCollapsed]));
|
| 585 |
+
const head = document.querySelector(`.tree-cat-head[data-tcat="${(window.CSS && CSS.escape) ? CSS.escape(cat) : cat}"]`);
|
| 586 |
+
if (head) { head.classList.toggle('collapsed'); head.nextElementSibling?.classList.toggle('collapsed'); }
|
| 587 |
}
|
| 588 |
|
| 589 |
/* ── TOPIC ARTICLE ─────────────────────────────────────── */
|
|
|
|
| 1203 |
try {
|
| 1204 |
const content = await getPageContent(path);
|
| 1205 |
const ids = new Set();
|
| 1206 |
+
const re = /\[source:([^\]\s]+)\]/g; let m, refs = 0;
|
| 1207 |
+
while ((m = re.exec(content))) { ids.add(m[1]); refs++; } // distinct → citedBy; occurrences → refCount
|
| 1208 |
ids.forEach(id => { if (!state.citedBy.has(id)) state.citedBy.set(id, new Set()); state.citedBy.get(id).add(path); });
|
| 1209 |
+
state.refCount.set(path, refs);
|
| 1210 |
+
state.wordCount.set(path, countWords(content));
|
| 1211 |
} catch (e) { /* skip unreadable article */ }
|
| 1212 |
}
|
| 1213 |
};
|
|
|
|
| 1219 |
state.citemapReady = true;
|
| 1220 |
refreshCitationViews();
|
| 1221 |
}
|
| 1222 |
+
// Prose word count — excludes frontmatter, code, math, citations, and markdown syntax.
|
| 1223 |
+
function countWords(md) {
|
| 1224 |
+
let t = String(md || '').replace(/^?---[\s\S]*?\n---\s*\n/, '');
|
| 1225 |
+
t = t.replace(/```[\s\S]*?```/g, ' ').replace(/\$\$[\s\S]*?\$\$/g, ' ').replace(/\$[^\n$]*?\$/g, ' ');
|
| 1226 |
+
t = t.replace(/\[source:[^\]]*\]/g, ' ').replace(/[#>*_`|~]+/g, ' ');
|
| 1227 |
+
return t.split(/\s+/).filter(w => /[A-Za-z0-9]/.test(w)).length;
|
| 1228 |
+
}
|
| 1229 |
+
const fmtNum = (n) => (n || 0).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
| 1230 |
+
|
| 1231 |
// Re-render whatever's on screen that depends on citation data, now that it's ready.
|
| 1232 |
function refreshCitationViews() {
|
| 1233 |
const r = parseHash();
|
styles.css
CHANGED
|
@@ -636,31 +636,48 @@ a:hover { color: var(--accent-deep); }
|
|
| 636 |
}
|
| 637 |
.list-meta .hint { color: var(--muted-5); }
|
| 638 |
|
| 639 |
-
/* ── Home: the
|
| 640 |
-
.
|
| 641 |
-
.
|
| 642 |
-
.
|
| 643 |
-
|
| 644 |
-
}
|
| 645 |
-
.
|
| 646 |
-
|
| 647 |
-
}
|
| 648 |
-
.
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
}
|
| 655 |
-
.
|
| 656 |
-
.
|
| 657 |
-
.
|
| 658 |
-
.
|
| 659 |
-
|
| 660 |
-
font-
|
| 661 |
-
}
|
| 662 |
-
.
|
| 663 |
-
.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 664 |
|
| 665 |
/* ── Sources sort switch ───────────────────────────────── */
|
| 666 |
.sort-switch { display: flex; gap: 0; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
|
|
|
|
| 636 |
}
|
| 637 |
.list-meta .hint { color: var(--muted-5); }
|
| 638 |
|
| 639 |
+
/* ── Home: the Contents tree (rollup words + references) ── */
|
| 640 |
+
.tree { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); box-shadow: var(--shadow); overflow: hidden; }
|
| 641 |
+
.tree-root {
|
| 642 |
+
font-family: var(--mono); font-size: 12.5px; color: var(--muted); padding: 12px 16px;
|
| 643 |
+
border-bottom: 1px solid var(--border); background: var(--bg-soft); font-variant-numeric: tabular-nums;
|
| 644 |
+
}
|
| 645 |
+
.tree-root b { color: var(--accent); font-weight: 600; }
|
| 646 |
+
.tree-cat { border-bottom: 1px solid var(--border-soft); }
|
| 647 |
+
.tree-cat:last-child { border-bottom: none; }
|
| 648 |
+
.tree-cat-head {
|
| 649 |
+
display: flex; align-items: baseline; gap: 9px; width: 100%; text-align: left; cursor: pointer;
|
| 650 |
+
background: none; border: none; padding: 10px 16px; transition: background .12s;
|
| 651 |
+
}
|
| 652 |
+
.tree-cat-head:hover { background: var(--bg-soft); }
|
| 653 |
+
.tree-cat-head .caret { font-size: 9px; color: var(--muted-4); transition: transform .15s; width: 9px; align-self: center; }
|
| 654 |
+
.tree-cat-head.collapsed .caret { transform: rotate(-90deg); }
|
| 655 |
+
.tree-cat-head .tc-name { font-family: var(--mono); font-size: 13.5px; font-weight: 600; color: var(--ink); }
|
| 656 |
+
.tree-cat-head .tc-frac { font-family: var(--mono); font-size: 10.5px; color: var(--muted-4); font-variant-numeric: tabular-nums; }
|
| 657 |
+
.tree-cat-head .tc-frac .w { color: var(--accent); }
|
| 658 |
+
.t-count {
|
| 659 |
+
margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--muted-2);
|
| 660 |
+
font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 12px;
|
| 661 |
+
}
|
| 662 |
+
.t-count b { color: var(--ink-3); font-weight: 600; }
|
| 663 |
+
.tree-cat-body { padding: 2px 16px 12px 30px; }
|
| 664 |
+
.tree-cat-body.collapsed { display: none; }
|
| 665 |
+
.tree-desc { font-size: 12px; color: var(--muted-2); line-height: 1.5; margin: 0 0 8px; max-width: 640px; }
|
| 666 |
+
.tree-leaf {
|
| 667 |
+
display: flex; align-items: baseline; gap: 8px; padding: 4px 6px; border-radius: 5px;
|
| 668 |
+
font-size: 13px; color: var(--ink-2); text-decoration: none; border-bottom: none;
|
| 669 |
+
}
|
| 670 |
+
a.tree-leaf { cursor: pointer; }
|
| 671 |
+
a.tree-leaf:hover { background: var(--bg-soft); color: var(--accent-deep); }
|
| 672 |
+
.tree-leaf .tl-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); flex: 0 0 auto; align-self: center; }
|
| 673 |
+
.tree-leaf .tl-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 674 |
+
.tree-leaf.planned { color: var(--muted-4); cursor: default; }
|
| 675 |
+
.tree-leaf.planned[title] { cursor: help; }
|
| 676 |
+
.tree-leaf .tl-dot.planned { background: none; border: 1px solid var(--muted-5); }
|
| 677 |
+
.tree-leaf .tl-tag { margin-left: auto; font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted-5); }
|
| 678 |
+
/* inline legend dots in the section lead */
|
| 679 |
+
.section-lead .tl-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--good); vertical-align: middle; margin: 0 2px; }
|
| 680 |
+
.section-lead .tl-dot.planned { background: none; border: 1px solid var(--muted-5); }
|
| 681 |
|
| 682 |
/* ── Sources sort switch ───────────────────────────────── */
|
| 683 |
.sort-switch { display: flex; gap: 0; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
|