MCPcopy Create free account
hub / github.com/cutedCha/noteBoook / renderTableOfContents

Function renderTableOfContents

js/app.js:1234–1341  ·  view source on GitHub ↗

* 渲染目录内容

()

Source from the content-addressed store, hash-verified

1232 * 渲染目录内容
1233 */
1234function renderTableOfContents() {
1235 console.log('=== renderTableOfContents 开始 ===');
1236
1237 // 使用 ID 选择器确保找到正确的元素
1238 const tocContent = document.getElementById('toc-content-container') || document.querySelector('.toc-content');
1239
1240 console.log('tocContent 元素:', tocContent);
1241
1242 if (!tocContent) {
1243 console.error('目录容器未找到!');
1244 return;
1245 }
1246
1247 console.log('当前 children.length:', tocContent.children.length);
1248 console.log('当前 innerHTML:', tocContent.innerHTML.substring(0, 100));
1249
1250 // 检查是否有 CHAPTERS_DATA(由 navigation.js 提供)
1251 console.log('CHAPTERS_DATA 是否存在:', typeof CHAPTERS_DATA !== 'undefined');
1252
1253 if (typeof CHAPTERS_DATA === 'undefined') {
1254 console.error('CHAPTERS_DATA 未定义!');
1255 tocContent.innerHTML = '<p style="padding: 20px; color: red; font-size: 18px;">错误:目录数据未加载</p>';
1256 return;
1257 }
1258
1259 console.log('CHAPTERS_DATA.length:', CHAPTERS_DATA.length);
1260
1261 // 清空并重新生成
1262 tocContent.innerHTML = '';
1263
1264 // 按分类组织章节
1265 const sections = {};
1266 CHAPTERS_DATA.forEach(chapter => {
1267 if (!sections[chapter.section]) {
1268 sections[chapter.section] = [];
1269 }
1270 sections[chapter.section].push(chapter);
1271 });
1272
1273 // 定义分类顺序
1274 const sectionOrder = [
1275 '基础概念篇',
1276 '效果原理篇',
1277 '进阶概念篇',
1278 '数学篇',
1279 '哲学彩蛋篇',
1280 '附录'
1281 ];
1282
1283 // 渲染各分类
1284 sectionOrder.forEach(sectionName => {
1285 const chapters = sections[sectionName];
1286 if (!chapters) return;
1287
1288 const sectionEl = document.createElement('div');
1289 sectionEl.className = 'toc-section';
1290
1291 const titleEl = document.createElement('h3');

Callers 1

showTableOfContentsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected