重做文章详情页:拾光阅读版式与目录/代码/灯箱交互
- 新增内容页外壳 base_content.html 与 reading.css / reading.js - 重写 post_detail.html:分类胶囊、阅读进度、首字下沉、代码块复制、 侧栏目录、上下篇、图片灯箱、明暗主题 - post_detail 视图补充上下篇、字数与阅读时长 - base.html 补 extra_css / extra_js block,修复脑图详情页样式不加载 - 加入 mindmaps、api、首页静态资源与模板 - 忽略 __pycache__ / *.pyc / *.back,并将已跟踪的 .pyc 移出版本库
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,635 @@
|
||||
/* =========================================================
|
||||
🎨 主题变量 —— 想换配色就只动这里
|
||||
========================================================= */
|
||||
:root[data-theme="light"] {
|
||||
--bg: #faf7f2; /* 羊皮纸暖底 */
|
||||
--bg-grain: rgba(180,150,110,.04); /* 纸张噪点 */
|
||||
--ink: #1f2937; /* 主文字 */
|
||||
--ink-soft: #6b7280;
|
||||
--ink-faint: #9ca3af;
|
||||
--line: #e5e1d8; /* 分隔线 */
|
||||
--card: #ffffff;
|
||||
--card-shadow: 0 1px 2px rgba(31,41,55,.04), 0 4px 16px rgba(31,41,55,.06);
|
||||
--card-shadow-hover: 0 4px 8px rgba(31,41,55,.06), 0 12px 28px rgba(31,41,55,.10);
|
||||
--accent: #c2542d; /* 赤陶橘:主强调色 */
|
||||
--accent-soft: rgba(194,84,45,.10);
|
||||
/* 调色板:鼠尾草/琥珀/赤陶/板岩/梅子 */
|
||||
--c1: #6b8f71; --c2: #d19a3f; --c3: #c2542d;
|
||||
--c4: #5b7a9d; --c5: #8d5a83; --c6: #4a9c94;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #0f1319;
|
||||
--bg-grain: rgba(255,255,255,.02);
|
||||
--ink: #e8e6e1;
|
||||
--ink-soft: #9ca3af;
|
||||
--ink-faint: #6b7280;
|
||||
--line: #232a33;
|
||||
--card: #1a1f27;
|
||||
--card-shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
|
||||
--card-shadow-hover: 0 4px 8px rgba(0,0,0,.35), 0 12px 28px rgba(0,0,0,.45);
|
||||
--accent: #e8956b;
|
||||
--accent-soft: rgba(232,149,107,.12);
|
||||
--c1: #7fae86; --c2: #e0b05c; --c3: #e8956b;
|
||||
--c4: #7a9fc4; --c5: #b07ba8; --c6: #6bb8af;
|
||||
}
|
||||
|
||||
* { margin:0; padding:0; box-sizing:border-box; }
|
||||
html, body { height:100%; overflow:hidden; }
|
||||
|
||||
body {
|
||||
font-family: 'Inter', -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--ink);
|
||||
transition: background .4s ease, color .4s ease;
|
||||
}
|
||||
/* 纸张噪点 + 柔和氛围光 */
|
||||
body::before {
|
||||
content:''; position:fixed; inset:0; pointer-events:none; z-index:0;
|
||||
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.35'/%3E%3C/svg%3E");
|
||||
opacity:.35; mix-blend-mode:multiply;
|
||||
}
|
||||
body::after {
|
||||
content:''; position:fixed; inset:0; pointer-events:none; z-index:0;
|
||||
background:
|
||||
radial-gradient(circle at 15% 20%, var(--accent-soft), transparent 45%),
|
||||
radial-gradient(circle at 85% 80%, color-mix(in srgb, var(--c4) 10%, transparent), transparent 45%);
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
顶部 / 底部
|
||||
========================================================= */
|
||||
header {
|
||||
position:fixed; top:0; left:0; right:0; z-index:10;
|
||||
display:flex; align-items:center; justify-content:space-between;
|
||||
padding: 18px 28px;
|
||||
background: linear-gradient(to bottom, var(--bg) 30%, transparent);
|
||||
pointer-events:none;
|
||||
}
|
||||
header > * { pointer-events:auto; }
|
||||
|
||||
.brand { display:flex; align-items:center; gap:12px; }
|
||||
.brand-mark {
|
||||
width:34px; height:34px; border-radius:10px;
|
||||
background: linear-gradient(135deg, var(--c3), var(--c2));
|
||||
display:grid; place-items:center; color:#fff;
|
||||
font-family:'Noto Serif SC', serif; font-weight:900; font-size:16px;
|
||||
box-shadow: var(--card-shadow);
|
||||
transition: transform .3s cubic-bezier(.2,1.2,.4,1);
|
||||
}
|
||||
.brand-mark:hover { transform: rotate(-6deg) scale(1.06); }
|
||||
.brand-text h1 {
|
||||
font-family:'Noto Serif SC', serif;
|
||||
font-size:17px; font-weight:700; letter-spacing:.5px;
|
||||
}
|
||||
.brand-text p { font-size:10.5px; color:var(--ink-faint); letter-spacing:3px; margin-top:1px; }
|
||||
|
||||
.top-actions { display:flex; gap:8px; align-items:center; }
|
||||
.icon-btn {
|
||||
width:34px; height:34px; border-radius:9px; border:1px solid var(--line);
|
||||
background: var(--card); color: var(--ink-soft); cursor:pointer;
|
||||
display:grid; place-items:center; font-size:14px;
|
||||
transition: all .18s ease;
|
||||
}
|
||||
.icon-btn:hover { color:var(--accent); border-color:var(--accent); transform:translateY(-1px); }
|
||||
.icon-btn.active { background:var(--accent); color:#fff; border-color:var(--accent); }
|
||||
|
||||
footer {
|
||||
position:fixed; bottom:18px; left:28px; z-index:10;
|
||||
font-size:11px; color:var(--ink-faint); letter-spacing:.5px;
|
||||
display:flex; align-items:center; gap:14px;
|
||||
}
|
||||
footer .dot { width:3px; height:3px; border-radius:50%; background:var(--ink-faint); }
|
||||
|
||||
/* =========================================================
|
||||
脑图容器
|
||||
========================================================= */
|
||||
#mindmap-wrap {
|
||||
position:absolute; inset:0; z-index:1;
|
||||
cursor:grab;
|
||||
}
|
||||
#mindmap-wrap.dragging { cursor:grabbing; }
|
||||
svg#mindmap { width:100%; height:100%; display:block; }
|
||||
|
||||
/* =========================================================
|
||||
Markmap 节点分层样式(核心)
|
||||
foreignObject 里的内容是 Markdown 渲染后的 HTML
|
||||
========================================================= */
|
||||
|
||||
/* —— 通用 —— */
|
||||
.markmap-foreign, .markmap-foreign * {
|
||||
font-family: inherit;
|
||||
color: var(--ink);
|
||||
transition: color .2s;
|
||||
}
|
||||
.markmap-foreign a { text-decoration:none; }
|
||||
|
||||
/* —— 根节点(depth-0):大标题胶囊 + 缓缓流动的鎏金 —— */
|
||||
.markmap-node-depth-0 .markmap-foreign {
|
||||
padding: 10px 22px !important;
|
||||
background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--c2)), var(--accent));
|
||||
background-size: 220% 220%;
|
||||
animation: nodeIn .5s cubic-bezier(.2,.8,.2,1) .05s backwards,
|
||||
rootShimmer 7s ease-in-out .05s infinite;
|
||||
border-radius: 999px;
|
||||
box-shadow: var(--card-shadow-hover),
|
||||
0 0 22px color-mix(in srgb, var(--accent) 22%, transparent);
|
||||
}
|
||||
@keyframes rootShimmer {
|
||||
0%,100% { background-position: 0% 50%; }
|
||||
50% { background-position: 100% 50%; }
|
||||
}
|
||||
.markmap-node-depth-0 .markmap-foreign *,
|
||||
.markmap-node-depth-0 text {
|
||||
color:#fff !important; fill:#fff !important;
|
||||
font-family:'Noto Serif SC', serif !important;
|
||||
font-size: 20px !important; font-weight: 900 !important;
|
||||
letter-spacing: 1.5px;
|
||||
}
|
||||
|
||||
/* —— 一级分类(depth-1):卡片 + 左侧色条 —— */
|
||||
.markmap-node-depth-1 .markmap-foreign {
|
||||
padding: 8px 16px 8px 14px !important;
|
||||
background: var(--card);
|
||||
border-radius: 12px;
|
||||
border-left: 3px solid var(--node-color, var(--accent));
|
||||
box-shadow: var(--card-shadow);
|
||||
font-size: 15px;
|
||||
transition: transform .2s ease, box-shadow .2s ease;
|
||||
}
|
||||
.markmap-node-depth-1 .markmap-foreign:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: var(--card-shadow-hover),
|
||||
0 0 14px color-mix(in srgb, var(--node-color, var(--accent)) 25%, transparent);
|
||||
}
|
||||
.markmap-node-depth-1 .markmap-foreign h2,
|
||||
.markmap-node-depth-1 .markmap-foreign strong {
|
||||
font-family:'Noto Serif SC', serif;
|
||||
font-size: 15.5px; font-weight: 700;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
/* —— 二级(depth-2):文章胶囊,可点击 —— */
|
||||
.markmap-node-depth-2 .markmap-foreign {
|
||||
padding: 4px 12px !important;
|
||||
background: color-mix(in srgb, var(--node-color, var(--accent)) 8%, var(--card));
|
||||
border: 1px solid color-mix(in srgb, var(--node-color, var(--accent)) 20%, transparent);
|
||||
border-radius: 999px;
|
||||
font-size: 13px; font-weight: 500;
|
||||
transition: transform .18s, background .18s, border-color .18s;
|
||||
}
|
||||
.markmap-node-depth-2 .markmap-foreign a { color: var(--ink); }
|
||||
.markmap-node-depth-2 .markmap-foreign:hover {
|
||||
transform: translateY(-1.5px) scale(1.02);
|
||||
background: color-mix(in srgb, var(--node-color, var(--accent)) 16%, var(--card));
|
||||
border-color: var(--node-color, var(--accent));
|
||||
}
|
||||
.markmap-node-depth-2 .markmap-foreign a:hover { color: var(--node-color, var(--accent)); }
|
||||
|
||||
/* —— 三级及以下(depth-3+):极简小标签 —— */
|
||||
.markmap-node-depth-3 .markmap-foreign,
|
||||
.markmap-node-depth-4 .markmap-foreign {
|
||||
padding: 2px 8px !important;
|
||||
font-size: 11.5px;
|
||||
color: var(--ink-soft) !important;
|
||||
font-weight: 400;
|
||||
letter-spacing: .3px;
|
||||
}
|
||||
.markmap-node-depth-3 .markmap-foreign a,
|
||||
.markmap-node-depth-4 .markmap-foreign a { color: var(--ink-soft); }
|
||||
.markmap-node-depth-3 .markmap-foreign a:hover { color: var(--accent); }
|
||||
|
||||
/* —— 节点圆点:按层级递减,hover 放大 —— */
|
||||
.markmap-node > circle {
|
||||
stroke-width: 2;
|
||||
stroke: var(--bg);
|
||||
filter: drop-shadow(0 1px 2px rgba(0,0,0,.12));
|
||||
transition: r .18s ease;
|
||||
}
|
||||
.markmap-node-depth-0 > circle { r: 0; } /* 根节点隐藏圆点 */
|
||||
.markmap-node-depth-1 > circle { r: 5; }
|
||||
.markmap-node-depth-2 > circle { r: 4; }
|
||||
.markmap-node-depth-3 > circle,
|
||||
.markmap-node-depth-4 > circle { r: 3; opacity:.7; }
|
||||
.markmap-node > circle:hover { r: 7; }
|
||||
|
||||
/* —— 分支连线:透明度随深度递减 —— */
|
||||
.markmap-link { fill:none; stroke-linecap: round; }
|
||||
.markmap-link-depth-0 { stroke-width: 2.4; opacity: .85; }
|
||||
.markmap-link-depth-1 { stroke-width: 1.8; opacity: .65; }
|
||||
.markmap-link-depth-2 { stroke-width: 1.3; opacity: .45; }
|
||||
.markmap-link-depth-3,
|
||||
.markmap-link-depth-4 { stroke-width: 1; opacity: .28; }
|
||||
|
||||
/* —— 入场级联动画 —— */
|
||||
@keyframes nodeIn {
|
||||
from { opacity: 0; transform: translateY(6px); }
|
||||
to { opacity: 1; transform: none; }
|
||||
}
|
||||
.markmap-node .markmap-foreign {
|
||||
animation: nodeIn .5s cubic-bezier(.2,.8,.2,1) backwards;
|
||||
}
|
||||
.markmap-node-depth-1 .markmap-foreign { animation-delay: .15s; }
|
||||
.markmap-node-depth-2 .markmap-foreign { animation-delay: .28s; }
|
||||
.markmap-node-depth-3 .markmap-foreign { animation-delay: .40s; }
|
||||
@keyframes lineIn { from { stroke-opacity: 0; } }
|
||||
.markmap-link { animation: lineIn .6s ease backwards; }
|
||||
|
||||
/* —— 搜索高亮 —— */
|
||||
.markmap-node.matched .markmap-foreign {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
border-radius: 999px;
|
||||
}
|
||||
.markmap-node.matched-dim { opacity: .25; transition: opacity .25s; }
|
||||
|
||||
/* =========================================================
|
||||
搜索框
|
||||
========================================================= */
|
||||
.search-box {
|
||||
position:fixed; top: 18px; left: 50%; transform: translateX(-50%) translateY(-8px);
|
||||
z-index: 20;
|
||||
display:flex; align-items:center; gap:8px;
|
||||
padding: 8px 14px;
|
||||
background: var(--card); border: 1px solid var(--line); border-radius: 999px;
|
||||
box-shadow: var(--card-shadow-hover);
|
||||
opacity:0; pointer-events:none;
|
||||
transition: all .22s cubic-bezier(.2,.8,.2,1);
|
||||
}
|
||||
.search-box.show { opacity:1; pointer-events:auto; transform: translateX(-50%) translateY(0); }
|
||||
.search-box input {
|
||||
border:none; outline:none; background:none;
|
||||
font: inherit; font-size: 13.5px; width: 220px; color: var(--ink);
|
||||
}
|
||||
.search-box kbd {
|
||||
font: 11px 'JetBrains Mono', monospace;
|
||||
padding: 2px 6px; border-radius:5px;
|
||||
background: var(--bg); color: var(--ink-faint); border:1px solid var(--line);
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
右下角工具栏
|
||||
========================================================= */
|
||||
.toolbar {
|
||||
position:fixed; right:20px; bottom:20px; z-index:20;
|
||||
display:flex; flex-direction:column; gap:6px;
|
||||
}
|
||||
.toolbar .icon-btn { width:36px; height:36px; font-size:14px; background:var(--card); }
|
||||
|
||||
/* =========================================================
|
||||
移动端
|
||||
========================================================= */
|
||||
@media (max-width: 720px) {
|
||||
header { padding: 12px 16px; }
|
||||
.brand-text p, .top-actions .hint { display:none; }
|
||||
footer { display:none; }
|
||||
.search-box input { width: 160px; }
|
||||
.markmap-node-depth-0 .markmap-foreign { font-size:17px !important; padding:8px 18px !important; }
|
||||
.markmap-node-depth-1 .markmap-foreign { font-size:13.5px; padding:6px 12px !important; }
|
||||
.markmap-node-depth-2 .markmap-foreign { font-size:12px; padding:3px 10px !important; }
|
||||
}
|
||||
/* 极光层 */
|
||||
.aurora {
|
||||
position: fixed; inset: -20%;
|
||||
z-index: 0; pointer-events: none;
|
||||
filter: blur(80px) saturate(140%);
|
||||
opacity: .55;
|
||||
animation: auroraShift 24s ease-in-out infinite alternate;
|
||||
}
|
||||
.aurora::before,
|
||||
.aurora::after {
|
||||
content: ''; position: absolute; border-radius: 50%;
|
||||
}
|
||||
.aurora::before {
|
||||
width: 55vw; height: 55vw;
|
||||
top: -10%; left: 5%;
|
||||
background: radial-gradient(circle at 30% 30%, var(--c3), transparent 65%);
|
||||
animation: blobA 18s ease-in-out infinite alternate;
|
||||
}
|
||||
.aurora::after {
|
||||
width: 45vw; height: 45vw;
|
||||
bottom: -15%; right: 5%;
|
||||
background: radial-gradient(circle at 60% 40%, var(--c4), transparent 65%);
|
||||
animation: blobB 22s ease-in-out infinite alternate;
|
||||
}
|
||||
.aurora > .blob-c {
|
||||
position: absolute;
|
||||
width: 40vw; height: 40vw;
|
||||
top: 30%; left: 35%;
|
||||
background: radial-gradient(circle at 50% 50%, var(--c6), transparent 65%);
|
||||
animation: blobC 26s ease-in-out infinite alternate;
|
||||
}
|
||||
|
||||
@keyframes auroraShift {
|
||||
from { transform: rotate(0deg) scale(1); }
|
||||
to { transform: rotate(8deg) scale(1.08); }
|
||||
}
|
||||
@keyframes blobA { from { transform: translate(0,0); } to { transform: translate(12vw, 8vh); } }
|
||||
@keyframes blobB { from { transform: translate(0,0); } to { transform: translate(-10vw, -6vh); } }
|
||||
@keyframes blobC { from { transform: translate(0,0) scale(1); } to { transform: translate(-8vw, 10vh) scale(1.15); } }
|
||||
|
||||
/* 暗色模式下极光更浓郁 */
|
||||
:root[data-theme="dark"] .aurora { opacity: .45; filter: blur(100px) saturate(160%); }
|
||||
|
||||
/* =========================================================
|
||||
🎬 开场引导层 · 「道生万物」
|
||||
========================================================= */
|
||||
:root { --intro-dur: 4600ms; }
|
||||
|
||||
.intro {
|
||||
position: fixed; inset: 0; z-index: 9999;
|
||||
display: grid; place-items: center;
|
||||
background: color-mix(in srgb, var(--bg) 86%, transparent);
|
||||
backdrop-filter: blur(24px) saturate(140%);
|
||||
-webkit-backdrop-filter: blur(24px) saturate(140%);
|
||||
transition: opacity .7s cubic-bezier(.4,0,.2,1),
|
||||
transform .7s cubic-bezier(.4,0,.2,1),
|
||||
filter .7s cubic-bezier(.4,0,.2,1);
|
||||
cursor: pointer;
|
||||
}
|
||||
.intro.leaving {
|
||||
opacity: 0; transform: scale(1.04); filter: blur(12px);
|
||||
pointer-events: none;
|
||||
}
|
||||
.intro-inner { display:flex; flex-direction:column; align-items:center; text-align:center; }
|
||||
|
||||
/* 内部元素级联入场 */
|
||||
.intro-inner > * { animation: introUp .8s cubic-bezier(.2,.8,.2,1) backwards; }
|
||||
.intro-inner > .intro-seed { animation-delay: .1s; }
|
||||
.intro-inner > .tao-phase { animation-delay: .15s; }
|
||||
.intro-inner > .intro-title { animation-delay: .35s; }
|
||||
.intro-inner > .intro-sub { animation-delay: .55s; }
|
||||
.intro-inner > .intro-divider { animation-delay: .7s; }
|
||||
.intro-inner > .intro-stats { animation-delay: .8s; }
|
||||
.intro-inner > .intro-progress { animation-delay: 1s; }
|
||||
.intro-inner > .intro-hint { animation-delay: 1.2s; }
|
||||
@keyframes introUp { from { opacity:0; transform: translateY(18px); } to { opacity:1; transform:none; } }
|
||||
|
||||
.intro-title {
|
||||
font-family:'Noto Serif SC', serif; font-weight:900;
|
||||
font-size: clamp(34px, 6vw, 56px);
|
||||
letter-spacing: .18em; margin: 16px 0 8px;
|
||||
background: linear-gradient(120deg, var(--ink) 20%, var(--accent) 75%, var(--c2));
|
||||
-webkit-background-clip: text; background-clip: text; color: transparent;
|
||||
filter: drop-shadow(0 0 18px color-mix(in srgb, var(--accent) 30%, transparent));
|
||||
}
|
||||
.intro-sub { color: var(--ink-soft); font-size: 14px; letter-spacing: .35em; text-indent: .35em; }
|
||||
|
||||
/* =========================================================
|
||||
✦ 道生万物 · 生成之树
|
||||
道(根) → 一 → 二(阴阳) → 三 → 万物(九叶)
|
||||
每一层等上一层生成完毕再依次展开,节奏即"生生不息"
|
||||
========================================================= */
|
||||
.intro-seed { width: 195px; height: 195px; animation: seedFloat 5s ease-in-out infinite alternate; }
|
||||
@keyframes seedFloat { from { transform: translateY(-4px) } to { transform: translateY(6px) } }
|
||||
.seed-svg { width:100%; height:100%; overflow: visible; }
|
||||
|
||||
/* —— SVG 渐变停靠点:颜色跟随主题变量 —— */
|
||||
.sgVine-a { stop-color: var(--accent); }
|
||||
.sgVine-b { stop-color: var(--c2); }
|
||||
.sgNode-a { stop-color: color-mix(in srgb, var(--c2) 55%, #fff); }
|
||||
.sgNode-b { stop-color: var(--accent); }
|
||||
.sgRoot-a { stop-color: color-mix(in srgb, var(--accent) 18%, #fff); }
|
||||
.sgRoot-b { stop-color: var(--c2); }
|
||||
.sgRoot-c { stop-color: var(--accent); }
|
||||
.sgHalo-a { stop-color: var(--accent); stop-opacity:.45; }
|
||||
.sgHalo-b { stop-color: var(--accent); stop-opacity:0; }
|
||||
|
||||
/* —— 缓旋虚线轨道 —— */
|
||||
.orbit {
|
||||
transform-box: fill-box; transform-origin: center;
|
||||
animation: orbitSpin 46s linear infinite, orbitFade 1.4s ease .2s backwards;
|
||||
}
|
||||
@keyframes orbitSpin { to { transform: rotate(360deg); } }
|
||||
@keyframes orbitFade { from { opacity: 0; } to { opacity: 1; } }
|
||||
.orbit circle {
|
||||
fill:none; stroke: var(--ink); opacity:.12; stroke-width:1;
|
||||
stroke-dasharray: .018 .03; stroke-linecap: round;
|
||||
}
|
||||
|
||||
/* —— 根部呼吸光晕 —— */
|
||||
.halo {
|
||||
fill: url(#sgHalo); stroke: none;
|
||||
transform-box: fill-box; transform-origin: center;
|
||||
animation: haloBreath 3s ease-in-out infinite;
|
||||
}
|
||||
@keyframes haloBreath {
|
||||
0%,100% { transform: scale(.9); opacity:.55; }
|
||||
50% { transform: scale(1.25); opacity:.95; }
|
||||
}
|
||||
|
||||
/* —— 双层声呐波纹(错峰扩散) —— */
|
||||
.sonar {
|
||||
fill: none; stroke: var(--accent); stroke-width: 1.5;
|
||||
transform-box: fill-box; transform-origin: center;
|
||||
animation: sonar 2.4s ease-out infinite;
|
||||
}
|
||||
.sonar.s-b { animation-delay: 1.2s; }
|
||||
@keyframes sonar { from { transform: scale(.6); opacity:.55 } to { transform: scale(2.4); opacity:0 } }
|
||||
|
||||
/* —— 藤蔓:渐变描边 + 辉光,按"世代"依次生长 —— */
|
||||
.sl {
|
||||
stroke: url(#sgVine); stroke-width: 2.3; stroke-linecap: round; fill: none;
|
||||
stroke-dasharray: 1; stroke-dashoffset: 1;
|
||||
filter: drop-shadow(0 0 4px color-mix(in srgb, var(--accent) 55%, transparent));
|
||||
animation: draw .8s cubic-bezier(.4,0,.2,1) forwards;
|
||||
}
|
||||
.sl.g1 { animation-delay:.45s; } /* 道生一 */
|
||||
.sl.g2 { animation-delay:1.25s; } /* 一生二 */
|
||||
.sl.g3 { animation-delay:2.05s; } /* 二生三 */
|
||||
@keyframes draw { to { stroke-dashoffset: 0 } }
|
||||
|
||||
/* —— 细枝:三生万物,九枝散叶 —— */
|
||||
.twig {
|
||||
stroke: var(--c2); stroke-width: 1.1; stroke-linecap: round; fill:none;
|
||||
opacity:.6; stroke-dasharray: 1; stroke-dashoffset: 1;
|
||||
animation: draw .5s ease forwards;
|
||||
}
|
||||
.twig.tw1 { animation-delay:2.95s } .twig.tw2 { animation-delay:3.02s }
|
||||
.twig.tw3 { animation-delay:3.09s } .twig.tw4 { animation-delay:3.16s }
|
||||
.twig.tw5 { animation-delay:3.23s } .twig.tw6 { animation-delay:3.30s }
|
||||
.twig.tw7 { animation-delay:3.37s } .twig.tw8 { animation-delay:3.44s }
|
||||
.twig.tw9 { animation-delay:3.51s }
|
||||
|
||||
/* —— 知识节点:渐变描边圆点,弹性绽放 —— */
|
||||
.sn {
|
||||
fill: var(--bg); stroke: url(#sgNode); stroke-width: 2.2;
|
||||
transform-box: fill-box; transform-origin: center;
|
||||
transform: scale(0);
|
||||
filter: drop-shadow(0 0 5px color-mix(in srgb, var(--accent) 55%, transparent));
|
||||
animation: pop .5s cubic-bezier(.2,1.4,.4,1) forwards;
|
||||
}
|
||||
.sn.n1 { animation-delay:.95s; } /* 一 */
|
||||
.sn.n2 { animation-delay:1.85s; } /* 二 */
|
||||
.sn.n3 { animation-delay:2.65s; } /* 三 */
|
||||
@keyframes pop { to { transform: scale(1) } }
|
||||
|
||||
/* —— 阴阳二仪:一空一盈 —— */
|
||||
.sn.yin { fill: var(--bg); stroke: url(#sgNode); }
|
||||
.sn.yang { fill: url(#sgNode); stroke: none; }
|
||||
|
||||
/* —— 根部:鎏光呼吸的「道」 —— */
|
||||
.sn.root {
|
||||
fill: url(#sgRoot); stroke: none;
|
||||
transform: scale(1);
|
||||
animation: rootPulse 2.2s ease-in-out infinite;
|
||||
filter: drop-shadow(0 0 10px color-mix(in srgb, var(--accent) 70%, transparent));
|
||||
}
|
||||
@keyframes rootPulse { 0%,100% { transform: scale(1) } 50% { transform: scale(1.16) } }
|
||||
|
||||
/* —— 万物之叶 —— */
|
||||
.lf {
|
||||
fill: var(--c2); stroke:none;
|
||||
transform-box: fill-box; transform-origin: center;
|
||||
transform: scale(0);
|
||||
filter: drop-shadow(0 0 4px color-mix(in srgb, var(--c2) 60%, transparent));
|
||||
animation: pop .45s cubic-bezier(.2,1.4,.4,1) forwards;
|
||||
}
|
||||
.lf.lf1 { animation-delay:3.35s } .lf.lf2 { animation-delay:3.42s }
|
||||
.lf.lf3 { animation-delay:3.49s } .lf.lf4 { animation-delay:3.56s }
|
||||
.lf.lf5 { animation-delay:3.63s } .lf.lf6 { animation-delay:3.70s }
|
||||
.lf.lf7 { animation-delay:3.77s } .lf.lf8 { animation-delay:3.84s }
|
||||
.lf.lf9 { animation-delay:3.91s }
|
||||
|
||||
/* —— 光尘:散落的时光正被拾起 —— */
|
||||
.dust {
|
||||
fill: var(--c2); opacity: 0;
|
||||
transform-box: fill-box; transform-origin: center;
|
||||
animation: dustFloat 4.5s ease-in infinite;
|
||||
}
|
||||
@keyframes dustFloat {
|
||||
0% { opacity:0; transform: translateY(10px) scale(.7); }
|
||||
25% { opacity:.9; }
|
||||
100% { opacity:0; transform: translateY(-30px) scale(1.2); }
|
||||
}
|
||||
|
||||
/* —— 流光:沿生成之路巡游的光点 —— */
|
||||
.spark {
|
||||
fill: var(--accent); stroke:none; opacity:0;
|
||||
filter: drop-shadow(0 0 5px var(--accent));
|
||||
animation: sparkLife 2.4s linear infinite;
|
||||
}
|
||||
@keyframes sparkLife {
|
||||
0% { opacity:0; } 12% { opacity:1; } 82% { opacity:1; } 100% { opacity:0; }
|
||||
}
|
||||
|
||||
/* —— 节点铭文:道 / 一 / 二 / 三 / 万物 —— */
|
||||
.lbl {
|
||||
font-family:'Noto Serif SC', serif; font-size:10px;
|
||||
fill: var(--ink-soft); opacity:0;
|
||||
animation: lblIn .7s ease forwards;
|
||||
}
|
||||
.lbl.l-wan { font-size:11px; fill: var(--accent); letter-spacing:2px; }
|
||||
.lbl.l-dao { animation-delay:.6s }
|
||||
.lbl.l-yi { animation-delay:1.15s }
|
||||
.lbl.l-er { animation-delay:2.05s }
|
||||
.lbl.l-san { animation-delay:2.85s }
|
||||
.lbl.l-wan { animation-delay:3.75s }
|
||||
@keyframes lblIn { from { opacity:0; transform: translateY(4px); } to { opacity:.8; transform:none; } }
|
||||
.lbl.l-wan { animation-name: lblInWan; }
|
||||
@keyframes lblInWan { from { opacity:0; transform: translateY(4px) scale(.9); } to { opacity:1; transform:none; } }
|
||||
|
||||
/* =========================================================
|
||||
✦ 生成之语:道生一 → 一生二 → 二生三 → 三生万物
|
||||
与树的展开节奏逐段同步(总时长 ≈ --intro-dur)
|
||||
========================================================= */
|
||||
.tao-phase {
|
||||
position:relative; width: 220px; height: 24px; margin: 2px 0 0;
|
||||
}
|
||||
.tao-phase span {
|
||||
position:absolute; inset:0; display:grid; place-items:center;
|
||||
font-family:'Noto Serif SC', serif;
|
||||
font-size:14px; letter-spacing:.5em; text-indent:.5em;
|
||||
color: var(--ink-soft);
|
||||
opacity:0;
|
||||
animation-duration: 4.6s;
|
||||
animation-timing-function: ease;
|
||||
animation-fill-mode: forwards;
|
||||
}
|
||||
.tao-phase span:nth-child(1) { animation-name: taoP1; }
|
||||
.tao-phase span:nth-child(2) { animation-name: taoP2; }
|
||||
.tao-phase span:nth-child(3) { animation-name: taoP3; }
|
||||
.tao-phase span:nth-child(4) { animation-name: taoP4; color: var(--accent); }
|
||||
@keyframes taoP1 { 0%{opacity:0} 5%{opacity:1} 18%{opacity:1} 25%{opacity:0} 100%{opacity:0} }
|
||||
@keyframes taoP2 { 0%{opacity:0} 23%{opacity:0} 29%{opacity:1} 40%{opacity:1} 47%{opacity:0} 100%{opacity:0} }
|
||||
@keyframes taoP3 { 0%{opacity:0} 43%{opacity:0} 49%{opacity:1} 60%{opacity:1} 67%{opacity:0} 100%{opacity:0} }
|
||||
@keyframes taoP4 { 0%{opacity:0} 64%{opacity:0} 71%{opacity:1} 100%{opacity:1} }
|
||||
|
||||
/* —— 数据统计:竖线分隔 + 数字鎏金渐变 —— */
|
||||
.intro-stats { display:flex; gap: 0; margin: 20px 0 28px; }
|
||||
.stat { display:flex; flex-direction:column; align-items:center; gap:4px; padding: 0 26px; position:relative; }
|
||||
.stat + .stat::before {
|
||||
content:''; position:absolute; left:0; top:18%; height:64%; width:1px;
|
||||
background: linear-gradient(180deg, transparent, var(--line) 30%, var(--line) 70%, transparent);
|
||||
}
|
||||
.stat b {
|
||||
font-family:'Noto Serif SC', serif; font-size: 26px; font-weight:900;
|
||||
background: linear-gradient(180deg, var(--ink) 30%, color-mix(in srgb, var(--accent) 60%, var(--ink)));
|
||||
-webkit-background-clip: text; background-clip: text; color: transparent;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.stat span { font-size: 11px; color: var(--ink-faint); letter-spacing: 2px; }
|
||||
|
||||
/* 进度条:时长由 JS 写入 --intro-dur,与自动跳转严格同步 */
|
||||
.intro-progress {
|
||||
width: 240px; height: 2px; border-radius: 2px; overflow: hidden;
|
||||
background: color-mix(in srgb, var(--ink) 12%, transparent);
|
||||
}
|
||||
.intro-progress i {
|
||||
display:block; height:100%; width:0; border-radius:2px;
|
||||
background: linear-gradient(90deg, var(--c3), var(--c2));
|
||||
box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
|
||||
animation: introProg var(--intro-dur) linear forwards;
|
||||
}
|
||||
@keyframes introProg { to { width: 100% } }
|
||||
|
||||
.intro-hint {
|
||||
margin-top: 12px; font-size: 11.5px; color: var(--ink-faint);
|
||||
letter-spacing: 3px; animation: hintBlink 2.4s ease-in-out infinite;
|
||||
}
|
||||
@keyframes hintBlink { 0%,100%{opacity:.45} 50%{opacity:1} }
|
||||
|
||||
.intro-skip {
|
||||
position: absolute; right: 28px; bottom: 26px;
|
||||
padding: 8px 18px; border-radius: 999px; cursor: pointer;
|
||||
background: transparent; color: var(--ink-soft);
|
||||
border: 1px solid var(--line);
|
||||
font-size: 12.5px; font-family: inherit; letter-spacing: 2px;
|
||||
transition: all .2s;
|
||||
}
|
||||
.intro-skip:hover { color: var(--accent); border-color: var(--accent); transform: translateX(-2px); }
|
||||
|
||||
/* —— 主页面在开场前"未聚焦",揭幕后聚焦呈现 —— */
|
||||
#mindmap-wrap, header, footer, .toolbar {
|
||||
opacity: 0; transform: scale(.975); filter: blur(8px);
|
||||
transition: opacity .9s ease .15s,
|
||||
transform .9s cubic-bezier(.2,.8,.2,1) .15s,
|
||||
filter .9s ease .15s;
|
||||
}
|
||||
body.intro-done #mindmap-wrap, body.intro-done header,
|
||||
body.intro-done footer, body.intro-done .toolbar {
|
||||
opacity: 1; transform: none; filter: none;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.stat { padding: 0 16px; }
|
||||
.stat b { font-size: 20px; }
|
||||
.intro-progress { width: 190px; }
|
||||
.intro-divider i { width: 44px; }
|
||||
.tao-phase { width: 180px; }
|
||||
.tao-phase span { font-size: 12.5px; }
|
||||
}
|
||||
|
||||
/* —— 无障碍:偏好减弱动效时,直接呈现生成完成的静帧 —— */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.intro-seed, .intro-hint, .sonar, .sn.root, .halo, .orbit,
|
||||
.dust, .spark, .intro-divider b,
|
||||
.markmap-node-depth-0 .markmap-foreign { animation: none !important; }
|
||||
.sl, .twig { animation: none !important; stroke-dashoffset: 0 !important; }
|
||||
.sn, .lf { animation: none !important; transform: none !important; opacity: 1 !important; }
|
||||
.lbl { animation: none !important; opacity: .8 !important; }
|
||||
.lbl.l-wan { opacity: 1 !important; }
|
||||
.tao-phase span { animation: none !important; opacity: 0 !important; }
|
||||
.tao-phase span:last-child { opacity: 1 !important; }
|
||||
.dust, .spark { opacity: 0 !important; }
|
||||
.intro, #mindmap-wrap, header, footer, .toolbar { transition-duration: .01s !important; }
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import os
|
||||
import re
|
||||
import urllib.request
|
||||
|
||||
# ==== 按你的实际路径改这三行 ====
|
||||
CSS_IN = 'fonts.css'
|
||||
CSS_OUT = 'fonts_out.css'
|
||||
FONT_DIR = './files'
|
||||
# ================================
|
||||
|
||||
UA = ('Mozilla/5.0 (Windows NT 10.0; Win64; x64) '
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')
|
||||
|
||||
os.makedirs(FONT_DIR, exist_ok=True)
|
||||
css = open(CSS_IN, encoding='utf-8').read()
|
||||
|
||||
pat = re.compile(r'url\((["\']?)(https://gstatic\.loli\.net/[^)"\']+)\1\)')
|
||||
urls = list(dict.fromkeys(m.group(2) for m in pat.finditer(css)))
|
||||
print(f'找到 {len(urls)} 个字体文件')
|
||||
|
||||
if not urls:
|
||||
raise SystemExit('没匹配到 gstatic 链接,检查 fonts.css 内容是否正常')
|
||||
|
||||
total = 0
|
||||
for i, u in enumerate(urls):
|
||||
name = f'{i:03d}.woff2'
|
||||
path = os.path.join(FONT_DIR, name)
|
||||
if not os.path.exists(path):
|
||||
req = urllib.request.Request(u, headers={'User-Agent': UA})
|
||||
with urllib.request.urlopen(req, timeout=60) as r, open(path, 'wb') as f:
|
||||
f.write(r.read())
|
||||
size = os.path.getsize(path)
|
||||
total += size
|
||||
css = css.replace(u, f'files/{name}') # 改成相对路径
|
||||
if (i + 1) % 20 == 0 or i == len(urls) - 1:
|
||||
print(f' {i+1}/{len(urls)} 累计 {total/1024/1024:.1f} MB')
|
||||
|
||||
open(CSS_OUT, 'w', encoding='utf-8').write(css)
|
||||
print('完成 →', CSS_OUT)
|
||||
Vendored
+2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,221 @@
|
||||
/* =========================================================
|
||||
0. 主题初始化(提前到数据加载之前,避免暗色用户先看到白屏闪烁)
|
||||
========================================================= */
|
||||
document.documentElement.dataset.theme =
|
||||
localStorage.getItem('theme') || 'light';
|
||||
|
||||
/* =========================================================
|
||||
1. 博客数据源:从 Django 后端接口拉取 Markdown
|
||||
后端视图见 sitemap_views.py,返回 text/markdown
|
||||
接口失败时用兜底数据渲染,保证页面不白屏
|
||||
========================================================= */
|
||||
const SITEMAP_API = '/api/sitemap/';
|
||||
|
||||
const FALLBACK_MARKDOWN = `
|
||||
# 我的博客
|
||||
|
||||
## 数据加载失败
|
||||
### 请稍后重试
|
||||
- [检查后端接口](/api/sitemap/)
|
||||
`;
|
||||
|
||||
async function loadMarkdown() {
|
||||
try {
|
||||
const res = await fetch(SITEMAP_API, { headers: { 'Accept': 'text/markdown' } });
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
const md = await res.text();
|
||||
if (!md.trim()) throw new Error('接口返回为空');
|
||||
return md;
|
||||
} catch (err) {
|
||||
console.error('[sitemap] 加载失败:', err);
|
||||
return FALLBACK_MARKDOWN;
|
||||
}
|
||||
}
|
||||
|
||||
const markdown = await loadMarkdown();
|
||||
|
||||
/* ============ 2. 解析 & 渲染 ============ */
|
||||
const { Transformer } = window.markmap;
|
||||
const { Markmap, deriveOptions } = window.markmap;
|
||||
const transformer = new Transformer();
|
||||
const { root } = transformer.transform(markdown);
|
||||
const svgEl = document.getElementById('mindmap');
|
||||
|
||||
// 调色板(与 CSS 变量同步;一级分类按索引取色,向下继承)
|
||||
const PALETTE = ['#6b8f71', '#d19a3f', '#c2542d', '#5b7a9d', '#8d5a83', '#4a9c94'];
|
||||
|
||||
// 给每个 depth-1 节点分配一个主题色,并通过 CSS 变量注入 foreignObject
|
||||
function paintBranches(node, color, depth = 0) {
|
||||
node.state = node.state || {};
|
||||
node.state.depth = depth;
|
||||
if (depth === 0) color = null;
|
||||
else if (depth === 1) color = PALETTE[(node.state.key ?? 0) % PALETTE.length];
|
||||
node.state.color = color || '#c2542d';
|
||||
(node.children || []).forEach((c, i) => {
|
||||
c.state = c.state || {};
|
||||
c.state.key = i;
|
||||
paintBranches(c, color, depth + 1);
|
||||
});
|
||||
}
|
||||
root.children?.forEach((c, i) => { c.state = { key: i }; paintBranches(c, null, 1); });
|
||||
|
||||
const mm = Markmap.create(svgEl, {
|
||||
duration: 380,
|
||||
maxWidth: 260,
|
||||
initialExpandLevel: 2,
|
||||
spacingHorizontal: 110,
|
||||
spacingVertical: 14,
|
||||
paddingX: 12,
|
||||
...deriveOptions({
|
||||
colorFreezeLevel: 2,
|
||||
linkShape: 'diagonal',
|
||||
}),
|
||||
color: (node) => node.state?.color ?? '#c2542d',
|
||||
}, root);
|
||||
|
||||
// 把当前节点的分支色注入到 foreignObject,驱动 CSS 的 --node-color
|
||||
function applyNodeColorVars() {
|
||||
svgEl.querySelectorAll('.markmap-node').forEach(g => {
|
||||
const depth = [...g.classList].find(c => c.startsWith('markmap-node-depth-'));
|
||||
if (!depth) return;
|
||||
const d = parseInt(depth.split('-').pop(), 10);
|
||||
const circle = g.querySelector(':scope > circle');
|
||||
const branchColor = circle ? circle.getAttribute('fill') : null;
|
||||
if (branchColor) g.style.setProperty('--node-color', branchColor);
|
||||
});
|
||||
}
|
||||
applyNodeColorVars();
|
||||
|
||||
mm.fit();
|
||||
|
||||
/* ============ 2.5 开场引导层(已移除数量统计逻辑) ============ */
|
||||
const INTRO_DURATION = 10000;
|
||||
const INTRO_EVERY_VISIT = true;
|
||||
const INTRO_KEY = 'intro-seen';
|
||||
const reduceMotion = matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
/* 揭幕时重播脑图级联入场动画 */
|
||||
function replayEntrance() {
|
||||
svgEl.querySelectorAll('.markmap-foreign, .markmap-link').forEach(el => {
|
||||
el.style.animation = 'none';
|
||||
void el.offsetWidth;
|
||||
el.style.animation = '';
|
||||
});
|
||||
}
|
||||
|
||||
const introEl = document.getElementById('intro');
|
||||
|
||||
function finishIntro() {
|
||||
if (!introEl || introEl.classList.contains('leaving')) return;
|
||||
introEl.classList.add('leaving');
|
||||
document.body.classList.add('intro-done');
|
||||
replayEntrance();
|
||||
setTimeout(() => { introEl.remove(); mm.fit(); }, 800);
|
||||
try { sessionStorage.setItem(INTRO_KEY, '1'); } catch {}
|
||||
}
|
||||
|
||||
(function startIntro() {
|
||||
let seen = null;
|
||||
try { seen = sessionStorage.getItem(INTRO_KEY); } catch {}
|
||||
const dur = (seen && !INTRO_EVERY_VISIT) || reduceMotion
|
||||
? Math.min(INTRO_DURATION, 900)
|
||||
: INTRO_DURATION;
|
||||
document.documentElement.style.setProperty('--intro-dur', dur + 'ms');
|
||||
|
||||
// 【已移除】countUp 数字滚动统计调用
|
||||
// 【已移除】footer 文章数同步
|
||||
|
||||
const timer = setTimeout(finishIntro, dur);
|
||||
const skip = () => { clearTimeout(timer); finishIntro(); };
|
||||
introEl.addEventListener('click', skip);
|
||||
document.getElementById('btnSkipIntro').addEventListener('click', (e) => {
|
||||
e.stopPropagation(); skip();
|
||||
});
|
||||
document.addEventListener('keydown', skip, { once: true });
|
||||
})();
|
||||
|
||||
/* ============ 3. 主题切换 ============ */
|
||||
const btnTheme = document.getElementById('btnTheme');
|
||||
btnTheme.onclick = () => {
|
||||
const cur = document.documentElement.dataset.theme;
|
||||
const next = cur === 'light' ? 'dark' : 'light';
|
||||
document.documentElement.dataset.theme = next;
|
||||
localStorage.setItem('theme', next);
|
||||
};
|
||||
|
||||
/* ============ 4. 搜索:匹配节点高亮 + 折叠其它 ============ */
|
||||
const searchBox = document.getElementById('searchBox');
|
||||
const searchInput = document.getElementById('searchInput');
|
||||
btnSearch.onclick = () => {
|
||||
searchBox.classList.toggle('show');
|
||||
if (searchBox.classList.contains('show')) searchInput.focus();
|
||||
else clearSearch();
|
||||
};
|
||||
searchInput.addEventListener('input', e => runSearch(e.target.value));
|
||||
searchInput.addEventListener('keydown', e => {
|
||||
if (e.key === 'Escape') { searchBox.classList.remove('show'); clearSearch(); }
|
||||
});
|
||||
document.addEventListener('keydown', e => {
|
||||
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'k') {
|
||||
e.preventDefault();
|
||||
btnSearch.click();
|
||||
}
|
||||
});
|
||||
|
||||
function runSearch(q) {
|
||||
clearSearch();
|
||||
if (!q.trim()) return;
|
||||
const kw = q.toLowerCase();
|
||||
const matched = [];
|
||||
svgEl.querySelectorAll('.markmap-node').forEach(g => {
|
||||
const fo = g.querySelector('.markmap-foreign');
|
||||
if (!fo) return;
|
||||
const text = fo.textContent.toLowerCase();
|
||||
if (text.includes(kw)) {
|
||||
g.classList.add('matched');
|
||||
matched.push(g);
|
||||
} else {
|
||||
g.classList.add('matched-dim');
|
||||
}
|
||||
});
|
||||
matched.forEach(g => {
|
||||
let p = g.parentElement;
|
||||
while (p && !p.classList.contains('markmap-node')) p = p.parentElement;
|
||||
});
|
||||
if (matched.length) {
|
||||
const first = matched[0].querySelector('.markmap-foreign');
|
||||
if (first) first.scrollIntoView({ behavior:'smooth', block:'center', inline:'center' });
|
||||
}
|
||||
}
|
||||
function clearSearch() {
|
||||
svgEl.querySelectorAll('.matched, .matched-dim').forEach(g =>
|
||||
g.classList.remove('matched', 'matched-dim'));
|
||||
}
|
||||
|
||||
/* ============ 5. 文章点击:接管路由 ============ */
|
||||
svgEl.addEventListener('click', e => {
|
||||
const a = e.target.closest('.markmap-foreign a');
|
||||
if (!a) return;
|
||||
e.preventDefault();
|
||||
window.open(a.getAttribute('href'), '_blank');
|
||||
});
|
||||
|
||||
/* ============ 6. 工具栏 ============ */
|
||||
const $ = id => document.getElementById(id);
|
||||
$('btnFit').onclick = () => mm.fit();
|
||||
$('btnIn').onclick = () => mm.rescale(1.2);
|
||||
$('btnOut').onclick = () => mm.rescale(1/1.2);
|
||||
$('btnFs').onclick = () => {
|
||||
if (!document.fullscreenElement) document.documentElement.requestFullscreen();
|
||||
else document.exitFullscreen();
|
||||
};
|
||||
|
||||
/* ============ 7. 响应式 + 拖拽反馈 ============ */
|
||||
let raf;
|
||||
window.addEventListener('resize', () => {
|
||||
cancelAnimationFrame(raf);
|
||||
raf = requestAnimationFrame(() => mm.fit());
|
||||
});
|
||||
const wrap = document.getElementById('mindmap-wrap');
|
||||
wrap.addEventListener('mousedown', () => wrap.classList.add('dragging'));
|
||||
window.addEventListener('mouseup', () => wrap.classList.remove('dragging'));
|
||||
@@ -0,0 +1,313 @@
|
||||
/* =========================================================
|
||||
拾光 · 阅读页交互
|
||||
1. 主题切换(与首页共享 localStorage 键名 theme)
|
||||
2. 顶栏滚动态 + 阅读进度
|
||||
3. 自动生成目录(侧栏 / 窄屏折叠)
|
||||
4. 代码块:语言标签 + 一键复制
|
||||
5. 表格横向滚动包裹
|
||||
6. 图片灯箱
|
||||
7. 键盘 ← → 翻上下篇
|
||||
无第三方依赖。
|
||||
========================================================= */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var root = document.documentElement;
|
||||
var bodyEl = document.body;
|
||||
|
||||
/* ---------- 1. 主题切换 ---------- */
|
||||
var btnTheme = document.getElementById('btnTheme');
|
||||
if (btnTheme) {
|
||||
btnTheme.addEventListener('click', function () {
|
||||
var next = root.dataset.theme === 'dark' ? 'light' : 'dark';
|
||||
root.dataset.theme = next;
|
||||
try { localStorage.setItem('theme', next); } catch (e) {}
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 2. 顶栏 + 阅读进度 ---------- */
|
||||
var head = document.getElementById('siteHead');
|
||||
var bar = document.getElementById('readProgress');
|
||||
var ticking = false;
|
||||
|
||||
function updateScrollUI() {
|
||||
var y = window.pageYOffset || document.documentElement.scrollTop || 0;
|
||||
|
||||
if (head) head.classList.toggle('is-scrolled', y > 8);
|
||||
|
||||
if (bar) {
|
||||
var doc = document.documentElement;
|
||||
var max = doc.scrollHeight - window.innerHeight;
|
||||
var p = max > 0 ? Math.min(1, Math.max(0, y / max)) : 0;
|
||||
bar.style.setProperty('--p', (p * 100).toFixed(2) + '%');
|
||||
}
|
||||
|
||||
spy();
|
||||
ticking = false;
|
||||
}
|
||||
|
||||
function onScroll() {
|
||||
if (ticking) return;
|
||||
ticking = true;
|
||||
window.requestAnimationFrame(updateScrollUI);
|
||||
}
|
||||
|
||||
/* ---------- 3. 目录 ---------- */
|
||||
var postBody = document.getElementById('postBody');
|
||||
var tocFixed = document.getElementById('toc');
|
||||
var tocMobile = document.getElementById('tocMobile');
|
||||
|
||||
var headings = postBody
|
||||
? [].slice.call(postBody.querySelectorAll('h1, h2, h3'))
|
||||
: [];
|
||||
|
||||
// 给标题补锚点 id
|
||||
headings.forEach(function (h, i) {
|
||||
if (!h.id) h.id = 'sec-' + (i + 1);
|
||||
});
|
||||
|
||||
function buildToc(list) {
|
||||
if (!list) return;
|
||||
var frag = document.createDocumentFragment();
|
||||
headings.forEach(function (h) {
|
||||
var li = document.createElement('li');
|
||||
li.className = 'toc-item depth-' + h.tagName.charAt(1);
|
||||
|
||||
var a = document.createElement('a');
|
||||
a.href = '#' + h.id;
|
||||
a.textContent = (h.textContent || '').trim().slice(0, 60) || '(无标题)';
|
||||
li.appendChild(a);
|
||||
frag.appendChild(li);
|
||||
});
|
||||
list.appendChild(frag);
|
||||
}
|
||||
|
||||
if (headings.length >= 2) {
|
||||
buildToc(tocFixed && tocFixed.querySelector('.toc-list'));
|
||||
buildToc(tocMobile && tocMobile.querySelector('.toc-list'));
|
||||
}
|
||||
|
||||
var tocLinks = [].slice.call(document.querySelectorAll('.toc-list a'));
|
||||
|
||||
// 侧栏目录只在足够宽时出现;窄屏用折叠目录
|
||||
function syncToc() {
|
||||
if (!tocFixed) return;
|
||||
var wide = window.innerWidth >= 1340;
|
||||
tocFixed.hidden = !(wide && headings.length >= 2);
|
||||
if (tocMobile) tocMobile.hidden = headings.length < 2;
|
||||
}
|
||||
|
||||
// 目录点击后收起折叠面板
|
||||
if (tocMobile) {
|
||||
tocMobile.addEventListener('click', function (e) {
|
||||
if (e.target.closest('a')) tocMobile.open = false;
|
||||
});
|
||||
}
|
||||
|
||||
// 滚动高亮当前章节
|
||||
function spy() {
|
||||
if (!tocLinks.length) return;
|
||||
var probe = window.innerHeight * 0.18 + 64;
|
||||
var current = null;
|
||||
for (var i = 0; i < headings.length; i++) {
|
||||
var h = headings[i];
|
||||
if (h.getBoundingClientRect().top <= probe) current = h;
|
||||
else break;
|
||||
}
|
||||
if (!current) current = headings[0];
|
||||
var currentId = current ? '#' + current.id : null;
|
||||
tocLinks.forEach(function (a) {
|
||||
a.classList.toggle('is-active', a.getAttribute('href') === currentId);
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 4. 代码块增强 ---------- */
|
||||
var LANG_NAMES = {
|
||||
python: 'Python', py: 'Python', cpp: 'C++', 'c++': 'C++', cxx: 'C++',
|
||||
c: 'C', vim: 'Vim', html: 'HTML', css: 'CSS', js: 'JavaScript',
|
||||
javascript: 'JavaScript', asm: 'ASM', bat: 'BAT', bash: 'Bash',
|
||||
shell: 'Shell', sh: 'Shell', markdown: 'Markdown', md: 'Markdown',
|
||||
note: 'Note', java: 'Java', sql: 'SQL', json: 'JSON', go: 'Go',
|
||||
rust: 'Rust', php: 'PHP', xml: 'XML', yaml: 'YAML', ini: 'INI'
|
||||
};
|
||||
|
||||
function copyText(text) {
|
||||
if (navigator.clipboard && window.isSecureContext !== false) {
|
||||
return navigator.clipboard.writeText(text);
|
||||
}
|
||||
return new Promise(function (resolve, reject) {
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
ta.setAttribute('readonly', '');
|
||||
ta.style.cssText = 'position:fixed;top:-999px;left:-999px;opacity:0';
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
try {
|
||||
document.execCommand('copy') ? resolve() : reject(new Error('copy failed'));
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
document.body.removeChild(ta);
|
||||
});
|
||||
}
|
||||
|
||||
function enhanceCode(pre) {
|
||||
var code = pre.querySelector('code');
|
||||
var cls = (code && code.getAttribute('class')) || pre.getAttribute('class') || '';
|
||||
var m = /language-([\w+#-]+)/i.exec(cls);
|
||||
var lang = m ? (LANG_NAMES[m[1].toLowerCase()] || m[1]) : '';
|
||||
|
||||
var wrap = document.createElement('div');
|
||||
wrap.className = 'code-block';
|
||||
|
||||
var barEl = document.createElement('div');
|
||||
barEl.className = 'code-bar';
|
||||
|
||||
var label = document.createElement('span');
|
||||
label.className = 'code-lang';
|
||||
label.textContent = lang || 'CODE';
|
||||
barEl.appendChild(label);
|
||||
|
||||
var btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'code-copy';
|
||||
btn.textContent = '复制';
|
||||
btn.setAttribute('aria-label', '复制这段代码');
|
||||
barEl.appendChild(btn);
|
||||
|
||||
pre.parentNode.insertBefore(wrap, pre);
|
||||
wrap.appendChild(barEl);
|
||||
wrap.appendChild(pre);
|
||||
|
||||
btn.addEventListener('click', function () {
|
||||
var text = (pre.innerText || pre.textContent || '').replace(/\n+$/, '');
|
||||
copyText(text).then(function () {
|
||||
btn.textContent = '已复制 ✓';
|
||||
btn.classList.add('is-done');
|
||||
window.setTimeout(function () {
|
||||
btn.textContent = '复制';
|
||||
btn.classList.remove('is-done');
|
||||
}, 1600);
|
||||
}).catch(function () {
|
||||
btn.textContent = '复制失败';
|
||||
window.setTimeout(function () { btn.textContent = '复制'; }, 1600);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (postBody) {
|
||||
[].slice.call(postBody.querySelectorAll('pre')).forEach(enhanceCode);
|
||||
}
|
||||
|
||||
/* ---------- 4.5 语法高亮(highlight.js 异步加载,加载失败则保持纯文本) ---------- */
|
||||
function highlightCode() {
|
||||
if (!window.hljs) return;
|
||||
[].slice.call(document.querySelectorAll('.post-body pre code')).forEach(function (code) {
|
||||
try { window.hljs.highlightElement(code); } catch (err) {}
|
||||
});
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', highlightCode);
|
||||
} else {
|
||||
highlightCode();
|
||||
}
|
||||
|
||||
/* ---------- 5. 表格横向滚动 ---------- */
|
||||
if (postBody) {
|
||||
[].slice.call(postBody.querySelectorAll('table')).forEach(function (table) {
|
||||
if (table.parentNode && table.parentNode.classList.contains('table-wrap')) return;
|
||||
var wrap = document.createElement('div');
|
||||
wrap.className = 'table-wrap';
|
||||
table.parentNode.insertBefore(wrap, table);
|
||||
wrap.appendChild(table);
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 6. 图片灯箱 ---------- */
|
||||
var lightbox = document.createElement('div');
|
||||
lightbox.className = 'lightbox';
|
||||
lightbox.hidden = true;
|
||||
lightbox.setAttribute('role', 'dialog');
|
||||
lightbox.setAttribute('aria-modal', 'true');
|
||||
lightbox.setAttribute('aria-label', '图片预览');
|
||||
lightbox.innerHTML =
|
||||
'<button class="lb-close" type="button" aria-label="关闭预览">✕</button>' +
|
||||
'<figure><img alt=""><figcaption></figcaption></figure>';
|
||||
|
||||
var lbImg = lightbox.querySelector('img');
|
||||
var lbCap = lightbox.querySelector('figcaption');
|
||||
document.body.appendChild(lightbox);
|
||||
|
||||
function openLightbox(src, caption) {
|
||||
lbImg.src = src;
|
||||
lbCap.textContent = caption && caption.toLowerCase() !== 'file' ? caption : '';
|
||||
lightbox.hidden = false;
|
||||
bodyEl.classList.add('no-scroll');
|
||||
root.classList.add('no-scroll');
|
||||
lightbox.querySelector('.lb-close').focus();
|
||||
}
|
||||
|
||||
function closeLightbox() {
|
||||
lightbox.hidden = true;
|
||||
lbImg.removeAttribute('src');
|
||||
bodyEl.classList.remove('no-scroll');
|
||||
root.classList.remove('no-scroll');
|
||||
}
|
||||
|
||||
if (postBody) {
|
||||
postBody.addEventListener('click', function (e) {
|
||||
var img = e.target.closest('img');
|
||||
if (!img) return;
|
||||
e.preventDefault();
|
||||
openLightbox(img.currentSrc || img.src, img.getAttribute('alt') || '');
|
||||
});
|
||||
}
|
||||
|
||||
lightbox.addEventListener('click', function (e) {
|
||||
if (e.target === lbImg) return;
|
||||
closeLightbox();
|
||||
});
|
||||
|
||||
/* ---------- 7. 键盘:← → 翻篇,Esc 关灯箱 ---------- */
|
||||
var prevLink = document.querySelector('.pager-item[data-nav="prev"]');
|
||||
var nextLink = document.querySelector('.pager-item[data-nav="next"]');
|
||||
|
||||
document.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Escape' && !lightbox.hidden) {
|
||||
closeLightbox();
|
||||
return;
|
||||
}
|
||||
if (e.metaKey || e.ctrlKey || e.altKey || e.shiftKey) return;
|
||||
|
||||
var t = e.target;
|
||||
if (t && t.closest && t.closest('input, textarea, select, [contenteditable="true"]')) return;
|
||||
if (!lightbox.hidden) return;
|
||||
|
||||
if (e.key === 'ArrowLeft' && prevLink) {
|
||||
window.location.href = prevLink.getAttribute('href');
|
||||
} else if (e.key === 'ArrowRight' && nextLink) {
|
||||
window.location.href = nextLink.getAttribute('href');
|
||||
}
|
||||
});
|
||||
|
||||
/* ---------- 8. 外链新窗口 ---------- */
|
||||
if (postBody) {
|
||||
[].slice.call(postBody.querySelectorAll('a[href]')).forEach(function (a) {
|
||||
if (/^https?:/i.test(a.href) && a.host !== window.location.host) {
|
||||
a.target = '_blank';
|
||||
a.rel = 'noopener noreferrer';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* ---------- 启动 ---------- */
|
||||
window.addEventListener('scroll', onScroll, { passive: true });
|
||||
window.addEventListener('resize', function () {
|
||||
syncToc();
|
||||
onScroll();
|
||||
});
|
||||
|
||||
syncToc();
|
||||
updateScrollUI();
|
||||
})();
|
||||
Reference in New Issue
Block a user