mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-blog.git
synced 2026-04-02 01:54:50 +00:00
added style to posts
This commit is contained in:
parent
4fb56b9888
commit
a0c13634f9
4 changed files with 146 additions and 44 deletions
|
|
@ -12,5 +12,8 @@ export default defineConfig({
|
|||
},
|
||||
},
|
||||
},
|
||||
site: "https://blog.cloverta.top"
|
||||
site: "https://blog.cloverta.top",
|
||||
redirects: {
|
||||
"/": "/zh",
|
||||
},
|
||||
})
|
||||
|
|
|
|||
|
|
@ -103,34 +103,38 @@ const switchHref = "/" + segments.join("/");
|
|||
</style>
|
||||
|
||||
<script is:inline>
|
||||
const theme = (() => {
|
||||
const localStorageTheme = localStorage?.getItem("theme") ?? "";
|
||||
if (["dark", "light"].includes(localStorageTheme)) {
|
||||
return localStorageTheme;
|
||||
}
|
||||
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
return "dark";
|
||||
}
|
||||
return "light";
|
||||
})();
|
||||
function applyTheme() {
|
||||
const localStorageTheme = localStorage?.getItem("theme") ?? "";
|
||||
let theme = "light";
|
||||
|
||||
if (theme === "light") {
|
||||
document.documentElement.classList.remove("dark");
|
||||
} else {
|
||||
document.documentElement.classList.add("dark");
|
||||
if (["dark", "light"].includes(localStorageTheme)) {
|
||||
theme = localStorageTheme;
|
||||
} else if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
||||
theme = "dark";
|
||||
}
|
||||
|
||||
document.documentElement.classList.toggle("dark", theme === "dark");
|
||||
window.localStorage.setItem("theme", theme);
|
||||
}
|
||||
|
||||
const handleToggleClick = () => {
|
||||
const element = document.documentElement;
|
||||
element.classList.toggle("dark");
|
||||
function bindThemeToggle() {
|
||||
const button = document.getElementById("themeToggle");
|
||||
if (!button) return;
|
||||
|
||||
const isDark = element.classList.contains("dark");
|
||||
localStorage.setItem("theme", isDark ? "dark" : "light");
|
||||
button.onclick = () => {
|
||||
const element = document.documentElement;
|
||||
element.classList.toggle("dark");
|
||||
|
||||
const isDark = element.classList.contains("dark");
|
||||
localStorage.setItem("theme", isDark ? "dark" : "light");
|
||||
};
|
||||
}
|
||||
|
||||
document
|
||||
.getElementById("themeToggle")
|
||||
?.addEventListener("click", handleToggleClick);
|
||||
applyTheme();
|
||||
bindThemeToggle();
|
||||
|
||||
document.addEventListener("astro:after-swap", () => {
|
||||
applyTheme();
|
||||
bindThemeToggle();
|
||||
});
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export default {
|
|||
},
|
||||
langSwitcher: "中文",
|
||||
home: {
|
||||
title: "Welcome in — mind the turn to the left",
|
||||
title: "Welcome in — please mind the gap",
|
||||
content: [
|
||||
"These few lines speak what the heart would say; Ink and paper end, but thoughts still stay",
|
||||
"Welcome to Cloverta's blog.",
|
||||
|
|
|
|||
|
|
@ -1,47 +1,142 @@
|
|||
---
|
||||
import BaseLayout from "./BaseLayout.astro";
|
||||
import Giscus from "@/components/Giscus.astro";
|
||||
import { getLangFromUrl, getTranslations } from "@/i18n";
|
||||
import "@/styles/global.css";
|
||||
|
||||
const { frontmatter } = Astro.props;
|
||||
const lang = getLangFromUrl(Astro.url);
|
||||
const t = getTranslations(lang);
|
||||
---
|
||||
|
||||
<BaseLayout pageTitle={frontmatter.title}>
|
||||
<h1>{frontmatter.title}</h1>
|
||||
<p>{frontmatter.pubDate.toLocaleDateString()}</p>
|
||||
<p><em>{frontmatter.description}</em></p>
|
||||
<p>Written by: {frontmatter.author}</p>
|
||||
<img src={frontmatter.image.url} width="300" alt={frontmatter.image.alt} />
|
||||
<div class="post-header">
|
||||
<div class="post-meta">
|
||||
<h1 class="post-title">{frontmatter.title}</h1>
|
||||
<p class="description"><em>{frontmatter.description}</em></p>
|
||||
<p class="meta-line">
|
||||
{t.post.publishedOn}: {frontmatter.pubDate.toLocaleDateString()}
|
||||
</p>
|
||||
<p class="meta-line">{t.post.writtenBy}: {frontmatter.author}</p>
|
||||
|
||||
<div class="tags">
|
||||
{
|
||||
frontmatter.tags.map((tag: string) => (
|
||||
<p class="tag">
|
||||
<a href={`/tags/${tag}`}>{tag}</a>
|
||||
</p>
|
||||
))
|
||||
}
|
||||
<div class="tags">
|
||||
{
|
||||
frontmatter.tags.map((tag: string) => (
|
||||
<p class="tag">
|
||||
<a href={`/${lang}/tags/${tag}`}>{tag}</a>
|
||||
</p>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<img
|
||||
src={frontmatter.image.url}
|
||||
alt={frontmatter.image.alt}
|
||||
class="post-cover"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<slot />
|
||||
|
||||
<Giscus />
|
||||
</BaseLayout>
|
||||
|
||||
<style>
|
||||
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 {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.4rem;
|
||||
margin-top: 0.8rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.tag {
|
||||
margin: 0.25em;
|
||||
border: dotted 1px #a1a1a1;
|
||||
border-radius: 0.5em;
|
||||
padding: 0.5em 1em;
|
||||
font-size: 1.15em;
|
||||
background-color: #f8fcfd;
|
||||
margin: 0;
|
||||
padding: 0.22em 0.65em;
|
||||
font-size: 0.88rem;
|
||||
line-height: 1.2;
|
||||
border: 1px dashed #8b6b4a;
|
||||
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>
|
||||
|
|
|
|||
Loading…
Reference in a new issue