全部笔记
\n' + escapeHtml(g.title) + '
- ' +
+ g.items.map(([text, file]) => `
- ${escapeHtml(text)} `).join('') + '
[\s\S]*?<\/p>/, ''); + fs.writeFileSync(path.join(dist, 'notes', 'index.html'), html); + return site + 'notes/'; +} + function build(dist, site, stubs) { const dir = path.join(dist, 'notes'); const names = fs.readdirSync(dir).filter(f => f.endsWith('.md')).map(f => f.slice(0, -3)).sort(); @@ -153,7 +174,7 @@ function build(dist, site, stubs) { fs.writeFileSync(path.join(dir, name + '.html'), page(rendered, name, site, stub)); if (!stub) urls.push(site + 'notes/' + route(name) + '.html'); } - return urls; + return [indexPage(dist, site)].concat(urls); } module.exports = { render, slugger, build }; diff --git a/website/builder/test_site_assets.py b/website/builder/test_site_assets.py index 33fef84e..17a1e822 100644 --- a/website/builder/test_site_assets.py +++ b/website/builder/test_site_assets.py @@ -98,10 +98,12 @@ class SearchIndexTests(unittest.TestCase): ''.join(f'## {t}\n\n内容\n\n' for t in titles[1:]) + 'HTML 链接\n\n```java\n# 不是标题\n```\n' (dist / 'notes' / '示例.md').write_text(body) (dist / 'notes' / '算法.md').write_text('见 [算法 - 目录](/notes/算法 - 目录.md)\n') + (dist / '_sidebar.md').write_text('- [首页](/)\n\n- **示例分组**\n - [示例](/notes/%E7%A4%BA%E4%BE%8B.md)\n') (dist / 'stubs.json').write_text(json.dumps({'/notes/算法': '/notes/算法 - 目录'}, ensure_ascii=False)) urls = json.loads(subprocess.run(['node', str(Path(__file__).parent / 'static_notes.cjs'), str(dist), 'https://example.com/', str(dist / 'stubs.json')], check=True, capture_output=True, text=True).stdout) - self.assertEqual(urls, ['https://example.com/notes/%E7%A4%BA%E4%BE%8B.html']) + self.assertEqual(urls, ['https://example.com/notes/', 'https://example.com/notes/%E7%A4%BA%E4%BE%8B.html']) + self.assertIn('示例', (dist / 'notes' / 'index.html').read_text()) page = (dist / 'notes' / '示例.html').read_text() counts = collections.Counter() expected = [heading_slug(t, counts) for t in titles] diff --git a/website/templates/index.html b/website/templates/index.html index c0c207fa..d88907bd 100644 --- a/website/templates/index.html +++ b/website/templates/index.html @@ -60,7 +60,7 @@