style(doc): 文档页面不再整体滚动,滚动条仅出现在侧边栏与正文区
- body 固定视口高度、flex 纵向布局并 overflow:hidden,页面级滚动条移除,sidebar/content 各自独立滚动(含移动端 40vh 侧边栏) - 标题下显示创建时间(创建于),正文末尾显示最后更新时间(新增 .doc-foot 样式) - 新增 @media print,打印时恢复自然文档流避免长文被固定高度裁切 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
2ed4fa8483
commit
0bb288dc86
@ -266,6 +266,7 @@ class DocSiteService extends Service {
|
|||||||
|
|
||||||
const rendered = markdown.render(this.stripLeadingTitle(current.content, current.title));
|
const rendered = markdown.render(this.stripLeadingTitle(current.content, current.title));
|
||||||
const toc = rendered.toc.filter(item => item.level >= 2 && item.level <= 4);
|
const toc = rendered.toc.filter(item => item.level >= 2 && item.level <= 4);
|
||||||
|
const created = dateOnly(current.createdAt || current.created_at);
|
||||||
const updated = dateOnly(current.updatedAt || current.updated_at);
|
const updated = dateOnly(current.updatedAt || current.updated_at);
|
||||||
const summary = current.summary || markdown.plainText(current.content, 140);
|
const summary = current.summary || markdown.plainText(current.content, 140);
|
||||||
|
|
||||||
@ -273,7 +274,7 @@ class DocSiteService extends Service {
|
|||||||
<header class="doc-head">
|
<header class="doc-head">
|
||||||
<h1>${escape(current.title)}</h1>
|
<h1>${escape(current.title)}</h1>
|
||||||
${summary ? `<p class="doc-summary">${escape(summary)}</p>` : ''}
|
${summary ? `<p class="doc-summary">${escape(summary)}</p>` : ''}
|
||||||
${updated ? `<p class="doc-meta">最近更新:${updated}</p>` : ''}
|
${created ? `<p class="doc-meta">创建于:${created}</p>` : ''}
|
||||||
</header>
|
</header>
|
||||||
<div class="doc-body">
|
<div class="doc-body">
|
||||||
${rendered.html}
|
${rendered.html}
|
||||||
@ -282,6 +283,7 @@ class DocSiteService extends Service {
|
|||||||
<div class="doc-toc__title">本页目录</div>
|
<div class="doc-toc__title">本页目录</div>
|
||||||
<ul>${toc.map(item => `<li class="lv-${item.level}"><a href="#${item.id}">${escape(item.text)}</a></li>`).join('')}</ul>
|
<ul>${toc.map(item => `<li class="lv-${item.level}"><a href="#${item.id}">${escape(item.text)}</a></li>`).join('')}</ul>
|
||||||
</nav>` : ''}
|
</nav>` : ''}
|
||||||
|
${updated ? `<p class="doc-foot">最后更新:${updated}</p>` : ''}
|
||||||
</article>`;
|
</article>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,21 +349,26 @@ ${this.styles()}
|
|||||||
--code-bg: #0f172a;
|
--code-bg: #0f172a;
|
||||||
}
|
}
|
||||||
* { box-sizing: border-box; }
|
* { box-sizing: border-box; }
|
||||||
html, body { margin: 0; padding: 0; }
|
html, body { margin: 0; padding: 0; height: 100%; }
|
||||||
body {
|
body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
background: #fff;
|
background: #fff;
|
||||||
line-height: 1.75;
|
line-height: 1.75;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
/* 页面本身不滚动,滚动条只出现在侧边栏与正文区 */
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
a { color: var(--brand); text-decoration: none; }
|
a { color: var(--brand); text-decoration: none; }
|
||||||
a:hover { text-decoration: underline; }
|
a:hover { text-decoration: underline; }
|
||||||
|
|
||||||
.topbar {
|
.topbar {
|
||||||
position: sticky;
|
position: relative;
|
||||||
top: 0;
|
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
flex: 0 0 auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 16px;
|
gap: 16px;
|
||||||
@ -409,14 +416,21 @@ a:hover { text-decoration: underline; }
|
|||||||
.layout {
|
.layout {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 248px minmax(0, 1fr);
|
grid-template-columns: 248px minmax(0, 1fr);
|
||||||
|
grid-template-rows: minmax(0, 1fr);
|
||||||
|
flex: 1 1 auto;
|
||||||
max-width: 1440px;
|
max-width: 1440px;
|
||||||
|
width: 100%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
min-height: calc(100vh - 56px - 60px);
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
.sidebar {
|
.sidebar {
|
||||||
padding: 24px 16px 40px;
|
padding: 24px 16px 40px;
|
||||||
background: var(--side-bg);
|
background: var(--side-bg);
|
||||||
border-right: 1px solid var(--border);
|
border-right: 1px solid var(--border);
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
}
|
}
|
||||||
.side-head {
|
.side-head {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
@ -445,7 +459,13 @@ a:hover { text-decoration: underline; }
|
|||||||
.side-link.is-active { background: var(--brand); color: #fff; }
|
.side-link.is-active { background: var(--brand); color: #fff; }
|
||||||
.side-empty { color: var(--text-muted); font-size: 13px; padding: 0 6px; }
|
.side-empty { color: var(--text-muted); font-size: 13px; padding: 0 6px; }
|
||||||
|
|
||||||
.content { padding: 32px 40px 64px; min-width: 0; }
|
.content {
|
||||||
|
padding: 32px 40px 64px;
|
||||||
|
min-width: 0;
|
||||||
|
min-height: 0;
|
||||||
|
overflow-y: auto;
|
||||||
|
overscroll-behavior: contain;
|
||||||
|
}
|
||||||
.doc { max-width: 820px; }
|
.doc { max-width: 820px; }
|
||||||
.doc-head h1 { font-size: 30px; line-height: 1.35; margin: 0 0 8px; }
|
.doc-head h1 { font-size: 30px; line-height: 1.35; margin: 0 0 8px; }
|
||||||
.doc-summary { margin: 0 0 6px; color: var(--text-muted); }
|
.doc-summary { margin: 0 0 6px; color: var(--text-muted); }
|
||||||
@ -498,11 +518,21 @@ a:hover { text-decoration: underline; }
|
|||||||
.doc-toc .lv-3 { padding-left: 14px; }
|
.doc-toc .lv-3 { padding-left: 14px; }
|
||||||
.doc-toc .lv-4 { padding-left: 28px; }
|
.doc-toc .lv-4 { padding-left: 28px; }
|
||||||
|
|
||||||
|
.doc-foot {
|
||||||
|
max-width: 820px;
|
||||||
|
margin: 32px 0 0;
|
||||||
|
padding-top: 16px;
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
font-size: 12.5px;
|
||||||
|
color: #94a3b8;
|
||||||
|
}
|
||||||
|
|
||||||
.empty { max-width: 720px; }
|
.empty { max-width: 720px; }
|
||||||
.empty h1 { font-size: 26px; }
|
.empty h1 { font-size: 26px; }
|
||||||
.empty p { color: var(--text-muted); }
|
.empty p { color: var(--text-muted); }
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
|
flex: 0 0 auto;
|
||||||
border-top: 1px solid var(--border);
|
border-top: 1px solid var(--border);
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@ -511,11 +541,28 @@ a:hover { text-decoration: underline; }
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 900px) {
|
@media (max-width: 900px) {
|
||||||
.layout { grid-template-columns: 1fr; }
|
.layout {
|
||||||
.sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
|
grid-template-columns: minmax(0, 1fr);
|
||||||
|
grid-template-rows: minmax(0, auto) minmax(0, 1fr);
|
||||||
|
}
|
||||||
|
.sidebar {
|
||||||
|
max-height: 40vh;
|
||||||
|
border-right: 0;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
padding: 16px 16px 20px;
|
||||||
|
}
|
||||||
.content { padding: 24px 20px 48px; }
|
.content { padding: 24px 20px 48px; }
|
||||||
.doc-head h1 { font-size: 24px; }
|
.doc-head h1 { font-size: 24px; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 打印时恢复自然文档流,避免长文被固定高度裁掉 */
|
||||||
|
@media print {
|
||||||
|
html, body { height: auto; overflow: visible; }
|
||||||
|
body { display: block; }
|
||||||
|
.topbar { position: static; }
|
||||||
|
.layout { display: block; overflow: visible; min-height: 0; }
|
||||||
|
.sidebar, .content { overflow: visible; max-height: none; height: auto; }
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user