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 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 summary = current.summary || markdown.plainText(current.content, 140);
|
||||
|
||||
@ -273,7 +274,7 @@ class DocSiteService extends Service {
|
||||
<header class="doc-head">
|
||||
<h1>${escape(current.title)}</h1>
|
||||
${summary ? `<p class="doc-summary">${escape(summary)}</p>` : ''}
|
||||
${updated ? `<p class="doc-meta">最近更新:${updated}</p>` : ''}
|
||||
${created ? `<p class="doc-meta">创建于:${created}</p>` : ''}
|
||||
</header>
|
||||
<div class="doc-body">
|
||||
${rendered.html}
|
||||
@ -282,6 +283,7 @@ class DocSiteService extends Service {
|
||||
<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>
|
||||
</nav>` : ''}
|
||||
${updated ? `<p class="doc-foot">最后更新:${updated}</p>` : ''}
|
||||
</article>`;
|
||||
}
|
||||
|
||||
@ -347,21 +349,26 @@ ${this.styles()}
|
||||
--code-bg: #0f172a;
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
html, body { margin: 0; padding: 0; }
|
||||
html, body { margin: 0; padding: 0; height: 100%; }
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||
color: var(--text);
|
||||
background: #fff;
|
||||
line-height: 1.75;
|
||||
font-size: 15px;
|
||||
/* 页面本身不滚动,滚动条只出现在侧边栏与正文区 */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
a { color: var(--brand); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
.topbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
position: relative;
|
||||
z-index: 10;
|
||||
flex: 0 0 auto;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
@ -409,14 +416,21 @@ a:hover { text-decoration: underline; }
|
||||
.layout {
|
||||
display: grid;
|
||||
grid-template-columns: 248px minmax(0, 1fr);
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
flex: 1 1 auto;
|
||||
max-width: 1440px;
|
||||
width: 100%;
|
||||
margin: 0 auto;
|
||||
min-height: calc(100vh - 56px - 60px);
|
||||
min-height: 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.sidebar {
|
||||
padding: 24px 16px 40px;
|
||||
background: var(--side-bg);
|
||||
border-right: 1px solid var(--border);
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
.side-head {
|
||||
font-size: 12px;
|
||||
@ -445,7 +459,13 @@ a:hover { text-decoration: underline; }
|
||||
.side-link.is-active { background: var(--brand); color: #fff; }
|
||||
.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-head h1 { font-size: 30px; line-height: 1.35; margin: 0 0 8px; }
|
||||
.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-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 h1 { font-size: 26px; }
|
||||
.empty p { color: var(--text-muted); }
|
||||
|
||||
.footer {
|
||||
flex: 0 0 auto;
|
||||
border-top: 1px solid var(--border);
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
@ -511,11 +541,28 @@ a:hover { text-decoration: underline; }
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.layout { grid-template-columns: 1fr; }
|
||||
.sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
|
||||
.layout {
|
||||
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; }
|
||||
.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