MCPcopy
hub / github.com/MisterBooo/LeetCodeAnimation / renderTopicIndex

Function renderTopicIndex

tools/scripts/sync-algomooc-index.js:152–185  ·  view source on GitHub ↗
(items)

Source from the content-addressed store, hash-verified

150}
151
152function renderTopicIndex(items) {
153 const groups = new Map();
154 for (const item of items) {
155 for (const topic of item.topicsZh) {
156 if (!groups.has(topic)) groups.set(topic, []);
157 groups.get(topic).push(item);
158 }
159 }
160
161 const sections = Array.from(groups.entries())
162 .sort((a, b) => b[1].length - a[1].length || a[0].localeCompare(b[0]))
163 .map(([topic, topicItems]) => {
164 const rows = topicItems
165 .sort((a, b) => a.leetcodeId - b.leetcodeId)
166 .map((item) => `| ${item.leetcodeId} | ${item.titleZh} | ${difficultyZh(item.difficulty)} | ${item.categoryZh} | [${item.slug}](${item.siteUrl}) |`);
167 return `## ${topic}(${topicItems.length})
168
169| # | 题目 | 难度 | 分类 | 网站路径 |
170| :-- | :-- | :-- | :-- | :-- |
171${rows.join("\n")}
172`;
173 });
174
175 return `# LeetCode 动画专题索引
176
177本文件由 \`tools/scripts/sync-algomooc-index.js\` 生成,按 \`docs/data/manifest.json\` 中的 \`topicsZh\` 分组。
178
179- LeetCode 题数:${items.length}
180- 专题数量:${groups.size}
181- 按题号查看:[\`docs/leetcode-animation-index.md\`](leetcode-animation-index.md)
182
183${sections.join("\n").trimEnd()}
184`;
185}
186
187function manifestText(items) {
188 return `${JSON.stringify(items, null, 2)}\n`;

Callers 1

Calls 2

difficultyZhFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected