Simplify strategy TOC to h2-only one level.

Drop nested h3 entries from the sidebar directory so the outline stays flat and easier to scan.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-07-18 17:37:39 +08:00
parent 9198aa0dcd
commit 023bf6a814
2 changed files with 21 additions and 18 deletions
+1 -1
View File
@@ -1385,7 +1385,7 @@
<script src="/assets/quotes.js?v=20260717-quotes-feed"></script>
<script src="/assets/funds.js?v=20260717-funds-scroll-fix"></script>
<script src="/assets/dashboard.js?v=20260717-dash-kpi-merge"></script>
<script src="/assets/strategy.js?v=6"></script>
<script src="/assets/strategy.js?v=7"></script>
<script src="/assets/help.js?v=1"></script>
<script src="/assets/logs.js?v=1"></script>
<script src="/assets/ai_review_render.js?v=3"></script>
+20 -17
View File
@@ -128,27 +128,17 @@
function buildDocToc() {
if (!docBody || !docToc) return;
const heads = Array.from(docBody.querySelectorAll("h2, h3"));
const heads = Array.from(docBody.querySelectorAll("h2"));
if (!heads.length) {
docToc.innerHTML = '<p class="strategy-empty">暂无目录</p>';
return;
}
let h2n = 0;
let h3n = 0;
const used = {};
const items = [];
heads.forEach((el) => {
const level = el.tagName === "H2" ? 2 : 3;
if (level === 2) {
h2n += 1;
h3n = 0;
} else {
if (!h2n) h2n = 1;
h3n += 1;
}
const num = level === 2 ? String(h2n) : h2n + "." + h3n;
let base = "st-" + num.replace(/\./g, "-") + "-" + slugify(el.textContent);
if (!base || base === "st-" + num.replace(/\./g, "-") + "-") base = "st-" + num.replace(/\./g, "-");
heads.forEach((el, idx) => {
const num = String(idx + 1);
let base = "st-" + num + "-" + slugify(el.textContent);
if (!base || base === "st-" + num + "-") base = "st-" + num;
let id = base;
let n = 2;
while (used[id] || document.getElementById(id)) {
@@ -157,12 +147,25 @@
}
used[id] = true;
el.id = id;
items.push({ level, num, id, text: (el.textContent || "").trim() });
items.push({ num, id, text: (el.textContent || "").trim() });
});
// 正文内 h3 仍保留锚点,便于日后扩展,但不进目录
Array.from(docBody.querySelectorAll("h3")).forEach((el, idx) => {
if (el.id) return;
let base = "st-h3-" + (idx + 1) + "-" + slugify(el.textContent);
if (!base || base.endsWith("-")) base = "st-h3-" + (idx + 1);
let id = base;
let n = 2;
while (document.getElementById(id)) {
id = base + "-" + n;
n += 1;
}
el.id = id;
});
docToc.innerHTML = items
.map(
(it) =>
`<a href="#${esc(it.id)}" class="strategy-toc-item level-${it.level}" data-id="${esc(it.id)}">` +
`<a href="#${esc(it.id)}" class="strategy-toc-item level-2" data-id="${esc(it.id)}">` +
`<span class="strategy-toc-num">${esc(it.num)}</span>` +
`<span class="strategy-toc-text">${esc(it.text)}</span></a>`
)