Skip to content

Commit 4ad30a6

Browse files
committed
Style(Blog): Change Blog`s Code box style
1 parent 6ce0a17 commit 4ad30a6

File tree

1 file changed

+197
-4
lines changed

1 file changed

+197
-4
lines changed

_layouts/post.html

Lines changed: 197 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
layout: default
33
---
44

5-
<article class="post-shell">
5+
<article class="post-shell" id="top">
66
<header class="post-header">
77
<p class="post-kicker">文章 / {% if page.categories.size > 0 %}{{ page.categories | join: " · " }}{% else %}未分类{% endif %}</p>
88
<h1 class="post-title">{{ page.title }}</h1>
@@ -51,11 +51,22 @@ <h1 class="post-title">{{ page.title }}</h1>
5151
</div>
5252

5353
<footer class="post-footer">
54-
<a href="javascript:history.back()" class="back-link">
55-
← 返回列表
56-
</a>
54+
<div class="post-footer-links">
55+
{% if page.previous and page.previous.url %}
56+
<a href="{{ page.previous.url | relative_url }}" class="back-link">← 上一篇</a>
57+
{% endif %}
58+
<a href="javascript:history.back()" class="back-link">← 返回列表</a>
59+
{% if page.next and page.next.url %}
60+
<a href="{{ page.next.url | relative_url }}" class="back-link">下一篇 →</a>
61+
{% endif %}
62+
<a href="#top" class="back-link">回到顶部</a>
63+
</div>
5764
</footer>
5865

66+
<button type="button" class="floating-back-to-top" id="floating-back-to-top" aria-label="返回顶部" title="返回顶部">
67+
<i class="fas fa-arrow-up"></i>
68+
</button>
69+
5970
<!--
6071
相关文章区域先注释掉,后续你要重做这里再打开即可。
6172
<section class="related-posts">
@@ -139,10 +150,40 @@ <h1 class="post-title">{{ page.title }}</h1>
139150
});
140151
}
141152

153+
function initFloatingBackToTop() {
154+
const button = document.getElementById('floating-back-to-top');
155+
if (!button) return;
156+
157+
const threshold = 320;
158+
let ticking = false;
159+
160+
const updateVisibility = () => {
161+
const shouldShow = window.scrollY > threshold;
162+
button.classList.toggle('is-visible', shouldShow);
163+
button.setAttribute('aria-hidden', shouldShow ? 'false' : 'true');
164+
ticking = false;
165+
};
166+
167+
const requestUpdate = () => {
168+
if (ticking) return;
169+
ticking = true;
170+
window.requestAnimationFrame(updateVisibility);
171+
};
172+
173+
button.addEventListener('click', () => {
174+
window.scrollTo({ top: 0, behavior: 'smooth' });
175+
});
176+
177+
window.addEventListener('scroll', requestUpdate, { passive: true });
178+
window.addEventListener('resize', requestUpdate);
179+
updateVisibility();
180+
}
181+
142182
function init() {
143183
initAnchors();
144184
initCodeBlocks();
145185
initReadingStats();
186+
initFloatingBackToTop();
146187
}
147188

148189
if (document.readyState === 'loading') {
@@ -271,6 +312,92 @@ <h1 class="post-title">{{ page.title }}</h1>
271312
margin: 0;
272313
}
273314

315+
.code-terminal-wrapper {
316+
margin: 22px 0;
317+
border: 1px solid var(--glass-border);
318+
border-radius: 16px;
319+
overflow: hidden;
320+
background: rgba(255, 255, 255, 0.76);
321+
box-shadow: var(--shadow);
322+
backdrop-filter: blur(10px);
323+
}
324+
325+
body.dark-mode .code-terminal-wrapper {
326+
background: rgba(17, 21, 28, 0.92);
327+
}
328+
329+
.code-terminal-header {
330+
display: flex;
331+
align-items: center;
332+
justify-content: space-between;
333+
gap: 12px;
334+
padding: 10px 14px;
335+
border-bottom: 1px solid var(--glass-border);
336+
background: rgba(0, 0, 0, 0.04);
337+
}
338+
339+
body.dark-mode .code-terminal-header {
340+
background: rgba(255, 255, 255, 0.04);
341+
}
342+
343+
.terminal-buttons {
344+
display: flex;
345+
align-items: center;
346+
gap: 7px;
347+
}
348+
349+
.terminal-buttons .btn {
350+
width: 12px;
351+
height: 12px;
352+
border-radius: 50%;
353+
display: inline-block;
354+
box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
355+
}
356+
357+
.terminal-buttons .btn.close { background: #ff5f57; }
358+
.terminal-buttons .btn.min { background: #febc2e; }
359+
.terminal-buttons .btn.max { background: #28c840; }
360+
361+
.copy-code-button {
362+
border: 1px solid var(--glass-border);
363+
background: rgba(255, 255, 255, 0.7);
364+
color: var(--text-main);
365+
border-radius: 999px;
366+
padding: 5px 12px;
367+
font-size: 0.8rem;
368+
cursor: pointer;
369+
transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
370+
}
371+
372+
body.dark-mode .copy-code-button {
373+
background: rgba(255, 255, 255, 0.06);
374+
color: var(--text-main);
375+
}
376+
377+
.copy-code-button:hover {
378+
background: var(--primary-color);
379+
color: #fff;
380+
border-color: var(--primary-color);
381+
}
382+
383+
.code-terminal-wrapper .post-content pre,
384+
.code-terminal-wrapper pre {
385+
margin: 0;
386+
padding: 0;
387+
border: 0;
388+
border-radius: 0;
389+
background: transparent;
390+
}
391+
392+
.code-terminal-wrapper pre code {
393+
display: block;
394+
padding: 18px 20px 20px;
395+
background: transparent;
396+
color: var(--text-main);
397+
font-family: 'Consolas', monospace;
398+
line-height: 1.75;
399+
}
400+
274401
.back-link {
275402
color: var(--primary-color);
276403
text-decoration: none;
@@ -284,9 +411,75 @@ <h1 class="post-title">{{ page.title }}</h1>
284411
text-align: center;
285412
}
286413

414+
.post-footer-links {
415+
display: flex;
416+
justify-content: center;
417+
gap: 18px;
418+
flex-wrap: wrap;
419+
}
420+
421+
.post-footer-links .back-link {
422+
font-weight: 700;
423+
}
424+
425+
.floating-back-to-top {
426+
position: fixed;
427+
right: 24px;
428+
bottom: 24px;
429+
width: 48px;
430+
height: 48px;
431+
border: 1px solid var(--glass-border);
432+
border-radius: 999px;
433+
background: rgba(255, 255, 255, 0.82);
434+
color: var(--primary-color);
435+
box-shadow: var(--shadow);
436+
display: flex;
437+
align-items: center;
438+
justify-content: center;
439+
cursor: pointer;
440+
z-index: 50;
441+
opacity: 0;
442+
transform: translateY(12px) scale(0.96);
443+
pointer-events: none;
444+
transition: opacity 0.2s ease, transform 0.2s ease, background 0.2s ease, color 0.2s ease;
445+
backdrop-filter: blur(8px);
446+
}
447+
448+
.floating-back-to-top:hover {
449+
background: var(--primary-color);
450+
color: #fff;
451+
}
452+
453+
body.dark-mode .floating-back-to-top {
454+
background: rgba(17, 21, 28, 0.9);
455+
color: var(--text-main);
456+
}
457+
458+
body.dark-mode .floating-back-to-top:hover {
459+
background: var(--primary-color);
460+
color: #fff;
461+
}
462+
463+
.floating-back-to-top.is-visible {
464+
opacity: 1;
465+
transform: translateY(0) scale(1);
466+
pointer-events: auto;
467+
}
468+
469+
.floating-back-to-top i {
470+
font-size: 0.95rem;
471+
}
472+
287473
@media (max-width: 900px) {
288474
.post-summary {
289475
text-align: left;
290476
}
477+
478+
.floating-back-to-top {
479+
right: 16px;
480+
bottom: 16px;
481+
width: 44px;
482+
height: 44px;
483+
}
291484
}
292485
</style>

0 commit comments

Comments
 (0)