Add section badges to strategy TOC/headings and fill cards to viewport height.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 策略说明:策略正文(博客目录 h2+h3) + 执行清单 Tab.
|
||||
* 策略说明:策略正文(目录 h2 + 章节标识) + 执行清单 Tab.
|
||||
*/
|
||||
(function () {
|
||||
const page = document.getElementById("page-strategy");
|
||||
@@ -126,6 +126,22 @@
|
||||
heads.forEach((h) => scrollSpyObs.observe(h));
|
||||
}
|
||||
|
||||
function sectionTag(title) {
|
||||
const t = String(title || "");
|
||||
if (/账户|定位/.test(t)) return "账户";
|
||||
if (/开仓类型|开仓|入场|反转|顺势|波段|假破|结构/.test(t)) return "入场";
|
||||
if (/周期/.test(t)) return "周期";
|
||||
if (/方向/.test(t)) return "方向";
|
||||
if (/纪律|出场|笔数|节奏/.test(t)) return "纪律";
|
||||
if (/持仓|离场|强平/.test(t)) return "离场";
|
||||
if (/资金|杠杆|计仓/.test(t)) return "仓位";
|
||||
if (/系统|字段|对接/.test(t)) return "系统";
|
||||
if (/修订|记录/.test(t)) return "版本";
|
||||
if (/边界|关系|行情状态/.test(t)) return "边界";
|
||||
if (/选择|如何/.test(t)) return "选择";
|
||||
return "章节";
|
||||
}
|
||||
|
||||
function buildDocToc() {
|
||||
if (!docBody || !docToc) return;
|
||||
const heads = Array.from(docBody.querySelectorAll("h2"));
|
||||
@@ -136,8 +152,10 @@
|
||||
const used = {};
|
||||
const items = [];
|
||||
heads.forEach((el, idx) => {
|
||||
const num = String(idx + 1);
|
||||
let base = "st-" + num + "-" + slugify(el.textContent);
|
||||
const num = String(idx + 1).padStart(2, "0");
|
||||
const text = (el.textContent || "").trim();
|
||||
const tag = sectionTag(text);
|
||||
let base = "st-" + num + "-" + slugify(text);
|
||||
if (!base || base === "st-" + num + "-") base = "st-" + num;
|
||||
let id = base;
|
||||
let n = 2;
|
||||
@@ -147,9 +165,17 @@
|
||||
}
|
||||
used[id] = true;
|
||||
el.id = id;
|
||||
items.push({ num, id, text: (el.textContent || "").trim() });
|
||||
if (!el.querySelector(".strategy-sec-mark")) {
|
||||
const mark = document.createElement("span");
|
||||
mark.className = "strategy-sec-mark";
|
||||
mark.setAttribute("aria-hidden", "true");
|
||||
mark.innerHTML =
|
||||
`<span class="strategy-sec-num">${esc(num)}</span>` +
|
||||
`<span class="strategy-sec-tag">${esc(tag)}</span>`;
|
||||
el.insertBefore(mark, el.firstChild);
|
||||
}
|
||||
items.push({ num, id, text, tag });
|
||||
});
|
||||
// 正文内 h3 仍保留锚点,便于日后扩展,但不进目录
|
||||
Array.from(docBody.querySelectorAll("h3")).forEach((el, idx) => {
|
||||
if (el.id) return;
|
||||
let base = "st-h3-" + (idx + 1) + "-" + slugify(el.textContent);
|
||||
@@ -165,8 +191,9 @@
|
||||
docToc.innerHTML = items
|
||||
.map(
|
||||
(it) =>
|
||||
`<a href="#${esc(it.id)}" class="strategy-toc-item level-2" data-id="${esc(it.id)}">` +
|
||||
`<a href="#${esc(it.id)}" class="strategy-toc-item" data-id="${esc(it.id)}">` +
|
||||
`<span class="strategy-toc-num">${esc(it.num)}</span>` +
|
||||
`<span class="strategy-toc-tag">${esc(it.tag)}</span>` +
|
||||
`<span class="strategy-toc-text">${esc(it.text)}</span></a>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
Reference in New Issue
Block a user