在阅读器中可以用目录和搜索、切换深色模式、练习这篇笔记中的面试题:打开《${escapeHtml(title)}》
([\s\S]*?)<\/p>/); return { html, title, description: para ? plain(para[1]).slice(0, 120) : title }; } const STYLE = ` :root { color-scheme: light dark; --bg: #f3f2ee; --surface: #fafbf8; --text: #34495e; --heading: #2c3e50; --muted: #5f6d66; --border: #dfe3da; --theme: #2a7a5a; --soft: #e7f1eb; --code: #9a3f2a; } @media (prefers-color-scheme: dark) { :root { --bg: #1a1d1c; --surface: #1f2422; --text: #c9d1cc; --heading: #e6ebe7; --muted: #98a59d; --border: #2f3633; --theme: #5cbf92; --soft: #23312b; --code: #e7a28f; } img { filter: brightness(.9); background: #ecebe6; } } * { box-sizing: border-box; } body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.95 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; -webkit-text-size-adjust: 100%; } a { color: var(--theme); text-underline-offset: 3px; } .top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--border); background: var(--bg); } .top .brand { color: var(--heading); font-weight: 700; text-decoration: none; } .top .all { margin-left: 14px; color: var(--muted); font-size: 14px; text-decoration: none; } .groups { columns: 2 240px; column-gap: 32px; }.groups section { break-inside: avoid; margin: 0 0 20px; }.groups h2 { margin: 0 0 6px; font-size: 1.05rem; border: 0; }.groups ul { margin: 0; padding-left: 20px; line-height: 1.9; } .open { display: inline-block; padding: 4px 12px; border: 1px solid var(--theme); border-radius: 6px; font-size: 14px; text-decoration: none; } main { max-width: 900px; margin: 0 auto; padding: 28px 24px 64px; } h1, h2, h3, h4, h5, h6 { color: var(--heading); line-height: 1.4; scroll-margin-top: 64px; } h1 { font-size: 2rem; margin: .4em 0 1em; } h2 { margin-top: 2.6rem; padding-bottom: .4rem; border-bottom: 1px solid var(--border); } img { max-width: 100%; height: auto; border-radius: 4px; } pre { overflow: auto; padding: 14px 16px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); line-height: 1.65; } code { font-family: "SFMono-Regular", Consolas, monospace; font-size: .88em; } :not(pre) > code { color: var(--code); overflow-wrap: anywhere; } table { display: block; overflow: auto; border-collapse: collapse; } pre:focus-visible, table:focus-visible { outline: 2px solid var(--theme); outline-offset: 2px; } td, th { padding: 6px 12px; border: 1px solid var(--border); } blockquote { margin: 1em 0; padding: 2px 16px; border-left: 4px solid var(--theme); background: var(--soft); } .toc { margin: 0 0 28px; padding: 6px 18px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }.toc summary { color: var(--theme); font-weight: 600; cursor: pointer; padding: 6px 0; }.toc a { text-decoration: none; }.toc ul { margin: 4px 0; line-height: 1.75; } .hot-1::after { content: " 🔥"; } .hot-2::after { content: " 🔥🔥"; } .qs { margin: -4px 0 16px; padding: 8px 14px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); font-size: 14.5px; }.qs b { color: var(--theme); font-size: 13px; }.qs ul { margin: 2px 0 0; padding-left: 18px; line-height: 1.8; }.qs a { text-decoration: none; } .reader { margin: 40px 0 0; padding: 14px 18px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 15px; } footer { padding: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 12px; text-align: center; } footer a { color: inherit; } @media (max-width: 640px) { main { padding: 20px 18px 48px; } h1 { font-size: 1.6rem; } .top { padding: 8px 14px; } } @media print { .top, .reader, footer { display: none; } body { background: #fff; } } `.replace(/\n\s*/g, ''); function page({ html, title, description }, name, site, stub) { const url = site + 'notes/' + route(name) + '.html'; const reader = '/#/notes/' + route(name); const canonical = stub ? site + 'notes/' + route(stub) + '.html' : url; return `
在阅读器中可以用目录和搜索、切换深色模式、练习这篇笔记中的面试题:打开《${escapeHtml(title)}》
[\s\S]*?<\/p>/, ''); fs.writeFileSync(path.join(dist, 'notes', 'index.html'), html); return site + 'notes/'; } function build(dist, site, stubs, sections) { sections = sections || {}; const dir = path.join(dist, 'notes'); const names = fs.readdirSync(dir).filter(f => f.endsWith('.md')).map(f => f.slice(0, -3)).sort(); const urls = []; for (const name of names) { const stub = stubs['/notes/' + name] && stubs['/notes/' + name].replace(/^\/notes\//, ''); const rendered = render(fs.readFileSync(path.join(dir, name + '.md'), 'utf8'), name, sections[name]); fs.writeFileSync(path.join(dir, name + '.html'), page(rendered, name, site, stub)); if (!stub) urls.push(site + 'notes/' + route(name) + '.html'); } return [indexPage(dist, site)].concat(urls); } module.exports = { render, slugger, build }; if (require.main === module) { const [dist, site, stubsFile, sectionsFile] = process.argv.slice(2); const stubs = stubsFile ? JSON.parse(fs.readFileSync(stubsFile, 'utf8')) : {}; const sections = sectionsFile ? JSON.parse(fs.readFileSync(sectionsFile, 'utf8')) : {}; process.stdout.write(JSON.stringify(build(dist, site, stubs, sections))); }