Merge branch 'master' into blog-content

This commit is contained in:
ClovertaTheTrilobita 2026-04-11 01:23:17 +03:00
commit 176e3d5fc4
5 changed files with 371 additions and 7 deletions

View file

@ -12,11 +12,10 @@ const data = Astro.props;
<div class="post-meta-row"> <div class="post-meta-row">
<span class="post-date">{data.date}</span> <span class="post-date">{data.date}</span>
<span class="post-stats"> <span class="post-stats">
<span class="post-stat" <span class="post-stat">
>💬 <Remark42Count url=`${data.postPath}` client:idle /></span 💬 <Remark42Count url={data.postPath} client:idle />
> </span>
</span> </span>
</div> </div>
</div> </div>
@ -122,10 +121,38 @@ const data = Astro.props;
@media (max-width: 640px) { @media (max-width: 640px) {
.post-link { .post-link {
gap: 0.75rem; display: grid;
grid-template-columns: 1fr 120px;
grid-template-areas:
"title title"
"desc image"
"meta image";
column-gap: 0.75rem;
row-gap: 0.2rem;
align-items: start;
}
.post-text {
display: contents;
min-height: auto;
}
.post-title {
grid-area: title;
-webkit-line-clamp: 2;
}
.post-description {
grid-area: desc;
}
.post-meta-row {
grid-area: meta;
gap: 0.7rem;
} }
.post-image { .post-image {
grid-area: image;
width: 120px; width: 120px;
height: calc(120px * 9 / 16); height: calc(120px * 9 / 16);
} }

View file

@ -22,6 +22,48 @@ const {
<meta name="generator" content={Astro.generator} /> <meta name="generator" content={Astro.generator} />
<title>{pageTitle}</title> <title>{pageTitle}</title>
</head> </head>
<div class="floating-actions">
<button
id="theme-toggle-fab"
aria-label="Toggle theme"
title="Toggle theme"
>
<svg
class="theme-toggle-icon"
viewBox="0 0 24 24"
width="20"
height="20"
aria-hidden="true"
>
<path
class="sun"
fill-rule="evenodd"
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"
></path>
<path
class="moon"
fill-rule="evenodd"
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"
></path>
</svg>
</button>
<button id="back-to-top" aria-label="Back to top" title="Back to top">
<svg
viewBox="0 0 24 24"
width="20"
height="20"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M18 15l-6-6-6 6"></path>
</svg>
</button>
</div>
<body> <body>
<Header /> <Header />
<main class="page-content"> <main class="page-content">
@ -38,4 +80,184 @@ const {
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.floating-actions {
position: fixed;
right: 1.25rem;
bottom: 1.25rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
z-index: 1000;
}
#theme-toggle-fab,
#back-to-top {
width: 3rem;
height: 3rem;
border: #a7a7a7 2px solid;
border-radius: 999px;
background: rgba(255, 255, 255, 0.92);
color: #222;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(6px);
}
#theme-toggle-fab {
position: relative;
}
#theme-toggle-fab {
position: relative;
}
.theme-toggle-icon {
width: 1.2rem;
height: 1.2rem;
fill: currentColor;
}
.theme-toggle-icon .sun,
.theme-toggle-icon .moon {
transform-origin: center;
transition:
opacity 0.2s ease,
transform 0.2s ease;
}
.theme-toggle-icon .sun {
opacity: 1;
transform: scale(1) rotate(0deg);
}
.theme-toggle-icon .moon {
opacity: 0;
transform: scale(0.75) rotate(-20deg);
}
:global(.dark) .theme-toggle-icon .sun {
opacity: 0;
transform: scale(0.75) rotate(20deg);
}
:global(.dark) .theme-toggle-icon .moon {
opacity: 1;
transform: scale(1) rotate(0deg);
}
#theme-toggle-fab,
#back-to-top {
opacity: 0;
visibility: hidden;
transform: translateY(10px);
transition:
opacity 0.2s ease,
transform 0.2s ease,
visibility 0.2s ease;
}
#theme-toggle-fab.show,
#back-to-top.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
#theme-toggle-fab.show:hover,
#back-to-top.show:hover {
transform: translateY(-2px);
}
:global(.dark) #theme-toggle-fab,
:global(.dark) #back-to-top {
background: rgba(34, 34, 34, 0.92);
color: #f5f5f5;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
border: #515151 2px solid;
}
@media (max-width: 640px) {
.floating-actions {
right: 1rem;
bottom: 1rem;
gap: 0.65rem;
}
#theme-toggle-fab,
#back-to-top {
width: 2.75rem;
height: 2.75rem;
}
}
</style> </style>
<script>
const initFloatingActions = () => {
const backToTop = document.getElementById("back-to-top");
const themeToggle = document.getElementById("theme-toggle-fab");
if (backToTop && backToTop.dataset.bound !== "true") {
const toggleBackToTop = () => {
if (window.scrollY > 300) {
backToTop.classList.add("show");
} else {
backToTop.classList.remove("show");
}
};
backToTop.addEventListener("click", () => {
window.scrollTo({
top: 0,
behavior: "smooth",
});
});
window.addEventListener("scroll", toggleBackToTop, {
passive: true,
});
toggleBackToTop();
backToTop.dataset.bound = "true";
}
if (themeToggle && themeToggle.dataset.bound !== "true") {
const togglethemeToggle = () => {
if (window.scrollY > 300) {
themeToggle.classList.add("show");
} else {
themeToggle.classList.remove("show");
}
};
const root = document.documentElement;
const applyTheme = (theme: string) => {
if (theme === "dark") {
root.classList.add("dark");
localStorage.setItem("color-theme", "dark");
} else {
root.classList.remove("dark");
localStorage.setItem("color-theme", "light");
}
};
themeToggle.addEventListener("click", () => {
const isDark = root.classList.contains("dark");
applyTheme(isDark ? "light" : "dark");
});
window.addEventListener("scroll", togglethemeToggle, {
passive: true,
});
togglethemeToggle();
themeToggle.dataset.bound = "true";
}
};
initFloatingActions();
document.addEventListener("astro:page-load", initFloatingActions);
</script>

View file

@ -14,6 +14,27 @@ const t = getTranslations(lang);
description={frontmatter.description} description={frontmatter.description}
image={frontmatter.image?.url} image={frontmatter.image?.url}
> >
<a
href="/"
class="back-button"
id="back-button"
aria-label="Go back"
title="返回"
>
<svg
viewBox="0 0 24 24"
width="20"
height="20"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M15 18l-6-6 6-6"></path>
</svg>
</a>
<article class="post-article"> <article class="post-article">
<div class="post-header"> <div class="post-header">
<div class="post-meta"> <div class="post-meta">
@ -81,7 +102,97 @@ const t = getTranslations(lang);
})} })}
/> />
<script>
const initFloatingActions = () => {
const backButton = document.getElementById("back-button");
if (backButton && backButton.dataset.bound !== "true") {
const toggleBackButton = () => {
if (window.scrollY > 300) {
backButton.classList.add("show");
} else {
backButton.classList.remove("show");
}
};
backButton.addEventListener("click", () => {
if (window.history.length > 1) {
window.history.back();
} else {
window.location.href = "/";
}
});
window.addEventListener("scroll", toggleBackButton, {
passive: true,
});
toggleBackButton();
backButton.dataset.bound = "true";
}
};
initFloatingActions();
document.addEventListener("astro:page-load", initFloatingActions);
</script>
<style> <style>
.back-button {
position: fixed;
top: 1.25rem;
left: 1.25rem;
width: 3rem;
height: 3rem;
border-radius: 999px;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
border: #285ee9 2px solid;
background: rgba(255, 255, 255, 0.92);
color: #222;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.16);
backdrop-filter: blur(6px);
z-index: 1000;
visibility: hidden;
transform: translateY(10px);
opacity: 0;
transition:
opacity 0.2s ease,
transform 0.2s ease,
visibility 0.2s ease;
box-shadow 0.2s ease,
background 0.2s ease,
color 0.2s ease;
}
.back-button.show {
opacity: 1;
visibility: visible;
transform: translateY(0);
}
.back-button.show:hover {
transform: translateY(-2px);
}
.back-button:hover {
transform: translateY(-2px);
}
:global(.dark) .back-button {
background: rgba(34, 34, 34, 0.92);
color: #f5f5f5;
box-shadow: 0 4px 14px rgba(0, 0, 0, 0.32);
border: #2f406d 2px solid;
}
@media (max-width: 640px) {
.back-button {
top: 1rem;
left: 1rem;
width: 2.75rem;
height: 2.75rem;
}
}
.post-content { .post-content {
font-family: font-family:
system-ui, system-ui,

View file

@ -44,9 +44,12 @@ const t = getTranslations(lang);
.toISOString() .toISOString()
.split("T")[0]; .split("T")[0];
const [postLang, ...slugParts] = post.id.split("/");
const slug = slugParts.join("/");
return ( return (
<PostItem <PostItem
url={`/${lang}/posts/${post.id}/`} url={`/${lang}/posts/${slug}/`}
title={post.data.title} title={post.data.title}
date={formattedDate} date={formattedDate}
img={post.data.image.url} img={post.data.image.url}

View file

@ -36,7 +36,7 @@ pre {
code { code {
font-family: "Maple Mono", monospace; font-family: "Maple Mono", monospace;
font-size: 0.92rem; font-size: 0.96rem;
} }
/* 行内代码 */ /* 行内代码 */
@ -61,6 +61,7 @@ body {
max-width: 90ch; max-width: 90ch;
padding: 1rem; padding: 1rem;
line-height: 1.7; line-height: 1.7;
font-size: 1.15rem;
} }
body::after { body::after {