added style to posts

This commit is contained in:
ClovertaTheTrilobita 2026-03-25 09:25:40 +02:00
parent 4fb56b9888
commit a0c13634f9
4 changed files with 146 additions and 44 deletions

View file

@ -12,5 +12,8 @@ export default defineConfig({
}, },
}, },
}, },
site: "https://blog.cloverta.top" site: "https://blog.cloverta.top",
redirects: {
"/": "/zh",
},
}) })

View file

@ -103,34 +103,38 @@ const switchHref = "/" + segments.join("/");
</style> </style>
<script is:inline> <script is:inline>
const theme = (() => { function applyTheme() {
const localStorageTheme = localStorage?.getItem("theme") ?? ""; const localStorageTheme = localStorage?.getItem("theme") ?? "";
let theme = "light";
if (["dark", "light"].includes(localStorageTheme)) { if (["dark", "light"].includes(localStorageTheme)) {
return localStorageTheme; theme = localStorageTheme;
} } else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
if (window.matchMedia("(prefers-color-scheme: dark)").matches) { theme = "dark";
return "dark";
}
return "light";
})();
if (theme === "light") {
document.documentElement.classList.remove("dark");
} else {
document.documentElement.classList.add("dark");
} }
document.documentElement.classList.toggle("dark", theme === "dark");
window.localStorage.setItem("theme", theme); window.localStorage.setItem("theme", theme);
}
const handleToggleClick = () => { function bindThemeToggle() {
const button = document.getElementById("themeToggle");
if (!button) return;
button.onclick = () => {
const element = document.documentElement; const element = document.documentElement;
element.classList.toggle("dark"); element.classList.toggle("dark");
const isDark = element.classList.contains("dark"); const isDark = element.classList.contains("dark");
localStorage.setItem("theme", isDark ? "dark" : "light"); localStorage.setItem("theme", isDark ? "dark" : "light");
}; };
}
document applyTheme();
.getElementById("themeToggle") bindThemeToggle();
?.addEventListener("click", handleToggleClick);
document.addEventListener("astro:after-swap", () => {
applyTheme();
bindThemeToggle();
});
</script> </script>

View file

@ -19,7 +19,7 @@ export default {
}, },
langSwitcher: "中文", langSwitcher: "中文",
home: { home: {
title: "Welcome in — mind the turn to the left", title: "Welcome in — please mind the gap",
content: [ content: [
"These few lines speak what the heart would say; Ink and paper end, but thoughts still stay", "These few lines speak what the heart would say; Ink and paper end, but thoughts still stay",
"Welcome to Cloverta's blog.", "Welcome to Cloverta's blog.",

View file

@ -1,47 +1,142 @@
--- ---
import BaseLayout from "./BaseLayout.astro"; import BaseLayout from "./BaseLayout.astro";
import Giscus from "@/components/Giscus.astro"; import Giscus from "@/components/Giscus.astro";
import { getLangFromUrl, getTranslations } from "@/i18n";
import "@/styles/global.css"; import "@/styles/global.css";
const { frontmatter } = Astro.props; const { frontmatter } = Astro.props;
const lang = getLangFromUrl(Astro.url);
const t = getTranslations(lang);
--- ---
<BaseLayout pageTitle={frontmatter.title}> <BaseLayout pageTitle={frontmatter.title}>
<h1>{frontmatter.title}</h1> <div class="post-header">
<p>{frontmatter.pubDate.toLocaleDateString()}</p> <div class="post-meta">
<p><em>{frontmatter.description}</em></p> <h1 class="post-title">{frontmatter.title}</h1>
<p>Written by: {frontmatter.author}</p> <p class="description"><em>{frontmatter.description}</em></p>
<img src={frontmatter.image.url} width="300" alt={frontmatter.image.alt} /> <p class="meta-line">
{t.post.publishedOn}: {frontmatter.pubDate.toLocaleDateString()}
</p>
<p class="meta-line">{t.post.writtenBy}: {frontmatter.author}</p>
<div class="tags"> <div class="tags">
{ {
frontmatter.tags.map((tag: string) => ( frontmatter.tags.map((tag: string) => (
<p class="tag"> <p class="tag">
<a href={`/tags/${tag}`}>{tag}</a> <a href={`/${lang}/tags/${tag}`}>{tag}</a>
</p> </p>
)) ))
} }
</div> </div>
</div>
<img
src={frontmatter.image.url}
alt={frontmatter.image.alt}
class="post-cover"
/>
</div>
<slot /> <slot />
<Giscus /> <Giscus />
</BaseLayout> </BaseLayout>
<style> <style>
a { a {
color: #00539f; color: var(--post-link-color);
}
.post-header {
display: grid;
grid-template-columns: minmax(0, 1fr) 300px;
align-items: start;
gap: 1.5rem;
margin-bottom: 1.5rem;
}
.post-meta {
min-width: 0;
}
.post-title {
margin: 0 0 0.5rem 0;
line-height: 1.25;
overflow-wrap: anywhere;
word-break: break-word;
}
.description {
margin: 0 0 0.7rem 0;
opacity: 0.9;
line-height: 1.6;
overflow-wrap: anywhere;
word-break: break-word;
}
.meta-line {
margin: 0.3rem 0;
line-height: 1.6;
overflow-wrap: anywhere;
word-break: break-word;
}
.post-cover {
width: 300px;
height: auto;
aspect-ratio: 16 / 9;
object-fit: cover;
object-position: center;
border-radius: 0.4rem;
display: block;
} }
.tags { .tags {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 0.4rem;
margin-top: 0.8rem;
min-width: 0;
} }
.tag { .tag {
margin: 0.25em; margin: 0;
border: dotted 1px #a1a1a1; padding: 0.22em 0.65em;
border-radius: 0.5em; font-size: 0.88rem;
padding: 0.5em 1em; line-height: 1.2;
font-size: 1.15em; border: 1px dashed #8b6b4a;
background-color: #f8fcfd; border-radius: 0;
background-color: transparent;
max-width: 100%;
}
.tag a {
color: #6f4e37;
text-decoration: none;
overflow-wrap: anywhere;
word-break: break-word;
}
.tag a:hover {
text-decoration: underline;
}
:global(.dark) .tag {
border-color: #d8c7a1;
}
:global(.dark) .tag a {
color: #e6d8b8;
}
@media (max-width: 560px) {
.post-header {
grid-template-columns: 1fr;
}
.post-cover {
width: 100%;
max-width: 100%;
}
} }
</style> </style>