From 023bf6a814997e839e3668fb410930aa0b70d444 Mon Sep 17 00:00:00 2001 From: dekun Date: Sat, 18 Jul 2026 17:37:39 +0800 Subject: [PATCH] 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 --- manual_trading_hub/static/index.html | 2 +- manual_trading_hub/static/strategy.js | 37 +++++++++++++++------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/manual_trading_hub/static/index.html b/manual_trading_hub/static/index.html index ceec44f..770a4e4 100644 --- a/manual_trading_hub/static/index.html +++ b/manual_trading_hub/static/index.html @@ -1385,7 +1385,7 @@ - + diff --git a/manual_trading_hub/static/strategy.js b/manual_trading_hub/static/strategy.js index 9008788..eb672c6 100644 --- a/manual_trading_hub/static/strategy.js +++ b/manual_trading_hub/static/strategy.js @@ -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 = '

暂无目录

'; 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) => - `` + + `` + `${esc(it.num)}` + `${esc(it.text)}` )