SanYeCao-blog/src/layouts/MarkdownPostLayout.astro

210 lines
4.2 KiB
Text
Raw Normal View History

2026-03-24 17:33:01 +00:00
---
2026-03-24 18:01:45 +00:00
import BaseLayout from "./BaseLayout.astro";
2026-03-24 18:39:50 +00:00
import Giscus from "@/components/Giscus.astro";
2026-03-25 07:25:40 +00:00
import { getLangFromUrl, getTranslations } from "@/i18n";
2026-03-24 18:01:45 +00:00
import "@/styles/global.css";
2026-03-25 07:25:40 +00:00
const { frontmatter, lang, postId } = Astro.props;
2026-03-25 07:25:40 +00:00
const t = getTranslations(lang);
2026-03-24 17:33:01 +00:00
---
2026-03-24 18:01:45 +00:00
2026-03-25 15:26:22 +00:00
<BaseLayout
pageTitle={frontmatter.title}
description={frontmatter.description}
image={frontmatter.image?.url}
>
<article class="post-article">
<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={`/${lang}/tags/${tag}`}>{tag}</a>
</p>
))
}
</div>
2026-03-25 07:25:40 +00:00
</div>
<img
src={frontmatter.image.url}
alt={frontmatter.image.alt}
class="post-cover"
/>
</div>
2026-03-24 18:01:45 +00:00
<div class="post-divider"></div>
<div class="post-content">
<slot />
</div>
2026-03-24 18:39:50 +00:00
<Giscus term={postId} />
</article>
2026-03-24 18:01:45 +00:00
</BaseLayout>
2026-03-25 07:25:40 +00:00
2026-03-25 15:26:22 +00:00
<script
type="application/ld+json"
set:html={JSON.stringify({
"@context": "https://schema.org",
"@type": "BlogPosting",
headline: frontmatter.title,
description: frontmatter.description,
image: frontmatter.image
? [
new URL(
frontmatter.image.url ?? frontmatter.image,
Astro.site,
).toString(),
]
: undefined,
datePublished: frontmatter.pubDate,
dateModified: frontmatter.updatedDate ?? frontmatter.pubDate,
author: {
"@type": "Person",
name: "CLoverta",
},
mainEntityOfPage: {
"@type": "WebPage",
"@id": new URL(Astro.url.pathname, Astro.site).toString(),
},
})}
/>
2026-03-24 18:01:45 +00:00
<style>
.post-content {
font-family:
system-ui,
-apple-system,
BlinkMacSystemFont,
"Segoe UI",
"PingFang SC",
"Hiragino Sans GB",
"Microsoft YaHei",
"Noto Sans CJK SC",
"Source Han Sans SC",
sans-serif;
}
.post-content :global(code),
.post-content :global(pre),
.post-content :global(kbd),
.post-content :global(samp) {
font-family: "Maple Mono", "Maple Mono CN", monospace;
}
2026-03-24 18:01:45 +00:00
a {
2026-03-25 07:25:40 +00:00
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;
2026-03-24 18:01:45 +00:00
}
.post-divider {
border-top: 1px dashed #dfe4e9;
margin: 1.2rem 0 1.5rem;
}
:global(.dark) .post-divider {
border-top-color: #7f91a3;
}
2026-03-24 18:01:45 +00:00
.tags {
display: flex;
flex-wrap: wrap;
2026-03-25 07:25:40 +00:00
gap: 0.4rem;
margin-top: 0.8rem;
min-width: 0;
2026-03-24 18:01:45 +00:00
}
.tag {
2026-03-25 07:25:40 +00:00
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%;
}
2026-03-24 18:01:45 +00:00
}
</style>