建站难度 · 进阶#网页#文档
单页文档 / 教程站生成
把一份资料变成带目录、搜索与代码高亮的单页文档站。
难度 进阶:需要准备素材或背景,产出要自己筛一遍才能用
适用工具ClaudeGeminiChatGPT
请把以下内容整理成一个单文件文档网页(index.html)。
内容:【粘贴你的教程 / 文档 / 笔记】。读者:【新手 / 有经验开发者】。
要求:
1. 结构化重排:层级清晰的小标题 + 目录侧栏(滚动高亮当前章节,移动端收起为顶部下拉)。
2. 代码块:语法高亮(highlight.js CDN),每块右上角复制按钮。
3. 搜索:顶部搜索框实时过滤章节(匹配标题与正文,命中处高亮)。
4. 阅读体验:正文最大宽度 720px 居中;重点步骤用有序列表;注意事项用引用块;表格保留并对齐。
5. 内容不改写事实,只做结构与措辞整理;原文含糊的地方加「(原文未说明)」标注而不是自行补造。
输出完整代码。文中【】为可替换变量,使用前请替换成你的具体内容。
变量填充:填一填直接用
已识别 2 个【】占位变量,填写后一键生成成品提示词;留空的变量所在行会自动删除,不会留下占位符。
示例输出
下面是按这条提示词填完后的实际产出,可直接对照判断该填成什么样。
产出的样子
```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Git 新手速成手册</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11/styles/github.min.css">
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11/lib/common.min.js"></script>
<style>
body { margin:0; font-family:system-ui,"PingFang SC",sans-serif; color:#1f2430;
background:#fafbfd; }
#side { position:fixed; top:0; left:0; bottom:0; width:230px; background:#fff;
border-right:1px solid #e5e7eb; padding:22px 16px; overflow-y:auto; }
#side h3 { font-size:15px; margin:0 0 12px; }
#side a { display:block; padding:6px 10px; font-size:13.5px; color:#4b5563;
text-decoration:none; border-radius:6px; margin-bottom:2px; }
#side a.on { background:#e8f0fe; color:#2563eb; font-weight:600; }
main { max-width:720px; margin:0 auto; padding:44px 22px 80px 266px; }
@media (max-width:900px) {
#side { position:static; width:auto; border-right:none; border-bottom:1px solid #e5e7eb; }
#side a { display:none; } #side a.on { display:block; }
main { padding:30px 22px 60px; } /* 移动端目录收起为当前章节 */
}
main { font-size:15.5px; line-height:1.75; }
h1 { font-size:26px; } h2 { font-size:20px; margin-top:2.2em; scroll-margin-top:16px; }
pre { position:relative; background:#f6f8fa; border-radius:10px; overflow:hidden; }
pre code { display:block; padding:16px 18px; overflow-x:auto; font-size:13.5px; }
.copy-btn { position:absolute; top:8px; right:8px; font-size:12px; padding:3px 10px;
background:#fff; border:1px solid #d0d7de; border-radius:6px; cursor:pointer; }
blockquote { margin:1em 0; padding:10px 16px; border-left:4px solid #f59e0b;
background:#fffbeb; border-radius:0 8px 8px 0; }
table { border-collapse:collapse; width:100%; font-size:14px; margin:1em 0; }
th, td { border:1px solid #e5e7eb; padding:8px 12px; text-align:left; }
#search { width:100%; box-sizing:border-box; padding:10px 14px; margin-bottom:16px;
border:1px solid #d0d7de; border-radius:8px; font-size:14px; }
mark { background:#fff176; }
</style>
</head>
<body>
<nav id="side">
<h3>目录</h3>
<div id="toc"></div>
</nav>
<main>
<input id="search" placeholder="搜索标题或正文…">
<div id="doc">
<h2 id="c1">1. 安装与配置</h2>
<p>安装 Git 后先设置身份信息,这两行配置会写进每个提交记录。</p>
<pre><code>git config --global user.name "你的名字"
git config --global user.email "you@example.com"</code></pre>
<blockquote>注意事项:email 建议与代码托管平台账号一致,否则贡献统计不归属到你。</blockquote>
<h2 id="c2">2. 日常三步走</h2>
<p>最常用的循环:改动 → 暂存 → 提交。</p>
<pre><code>git add README.md # 暂存单个文件
git commit -m "修复首页错别字"</code></pre>
<h2 id="c3">3. 分支操作</h2>
<p>(原文未说明)在团队协作时应从主分支拉出功能分支,完成后合并回去。</p>
<pre><code>git switch -c feature/login # 新建并切换分支
git switch main # 切回主分支
git merge feature/login # 合并</code></pre>
<table>
<thead><tr><th>命令</th><th>作用</th><th>风险等级</th></tr></thead>
<tbody>
<tr><td>git switch</td><td>切换分支</td><td>低</td></tr>
<tr><td>git merge</td><td>合并分支</td><td>中(冲突需手动解决)</td></tr>
<tr><td>git reset --hard</td><td>丢弃全部改动</td><td>高</td></tr>
</tbody>
</table>
</div>
</main>
<script>
// 目录生成 + 滚动高亮
const heads = [...document.querySelectorAll('#doc h2')];
const toc = document.getElementById('toc');
toc.innerHTML = heads.map(h => '<a href="#' + h.id + '">' + h.textContent + '</a>').join('');
const links = [...toc.querySelectorAll('a')];
const io = new IntersectionObserver(es => {
es.forEach(e => {
if (e.isIntersecting) {
links.forEach(a => a.classList.toggle('on', a.getAttribute('href') === '#' + e.target.id));
}
});
}, { rootMargin: '-10% 0px -80% 0px' });
heads.forEach(h => io.observe(h));
// 代码高亮 + 复制按钮
document.querySelectorAll('pre code').forEach(block => {
hljs.highlightElement(block);
const pre = block.parentElement, btn = document.createElement('button');
btn.className = 'copy-btn'; btn.textContent = '复制';
btn.onclick = () => {
navigator.clipboard.writeText(block.textContent).then(() => {
btn.textContent = '已复制'; setTimeout(() => btn.textContent = '复制', 1500);
});
};
pre.appendChild(btn);
});
// 实时搜索:匹配标题与正文,命中高亮
const search = document.getElementById('search');
search.addEventListener('input', () => {
const q = search.value.trim().toLowerCase();
heads.forEach(h => {
const sec = h, hit = !q || h.textContent.toLowerCase().includes(q) ||
h.nextElementSibling?.textContent?.toLowerCase().includes(q);
sec.style.display = hit ? '' : 'none';
});
document.querySelectorAll('#doc mark').forEach(m => m.outerHTML = m.textContent);
if (q) {
const walker = document.createTreeWalker(document.getElementById('doc'), NodeFilter.SHOW_TEXT);
const nodes = [];
while (walker.nextNode()) {
if (walker.currentNode.textContent.toLowerCase().includes(q) &&
walker.currentNode.parentElement.tagName !== 'SCRIPT') nodes.push(walker.currentNode);
}
nodes.forEach(n => n.parentElement.innerHTML =
n.parentElement.innerHTML.replace(new RegExp('(' + q.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi'), '<mark>$1</mark>'));
}
});
</script>
</body>
</html>
```
**实现说明**
- 结构化重排:h2 分章 + 左侧目录,滚动用 IntersectionObserver 高亮当前章节;移动端目录收起、只显示当前章节。
- 代码块走 highlight.js CDN 高亮,右上角复制按钮带「已复制」反馈。
- 搜索框实时过滤章节(匹配标题与正文),命中文字 mark 高亮,清空搜索自动还原。
- 正文 720px 居中、行高 1.75、重点表格保留对齐、注意事项引用块;「原文未说明」处已按约定标注而非自行补造。目录滚动高亮、移动端收起、highlight.js + 复制按钮、实时搜索高亮四项功能齐备,720px 阅读宽度与引用块/表格排版符合要求,原文含糊处用「(原文未说明)」标注。
什么时候会翻车:highlight.js 的 CDN 语言包不是全量引入,代码高亮只对部分语言生效;实时搜索过滤章节模型写的匹配只看标题,正文搜索可能落空。
想一次试多种填法做 A/B 对比?把这条提示词粘进Prompt 变量模板填充,把要换的部分写成 {{变量}},会自动生成表单并批量渲染出多个版本。
使用技巧
- 「不改写事实 + 含糊处标注」能防止整理文档时被模型悄悄改错参数。
- 内容很长时分两次发,先发一半说「先出结构」,再补其余。
这条提示词收录在 1 套精选合集里
合集按真实工作流排好了前后顺序,点进合集可以看「它前面该做什么、后面接什么」。
同类提示词
动手做:配套工具
这条提示词是成品,下面几个工具能把它变成你要的那一版。
