2023-08-31 03:47:22 +00:00
|
|
|
---
|
2023-08-31 08:07:03 +00:00
|
|
|
import "../../styles/post.scss";
|
2023-08-31 03:47:22 +00:00
|
|
|
import BaseLayout from "../../layouts/BaseLayout.astro";
|
|
|
|
import { type CollectionEntry, getCollection } from "astro:content";
|
2023-08-31 08:07:03 +00:00
|
|
|
import Timestamp from "../../components/Timestamp.astro";
|
2023-08-31 15:33:14 +00:00
|
|
|
import { getImage } from "astro:assets";
|
2023-09-01 17:38:59 +00:00
|
|
|
import TocWrapper from "../../components/TocWrapper.astro";
|
2023-08-31 03:47:22 +00:00
|
|
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
const posts = await getCollection("posts");
|
|
|
|
return posts.map((post) => ({
|
|
|
|
params: { slug: post.slug },
|
|
|
|
props: post,
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
type Props = CollectionEntry<"posts">;
|
|
|
|
|
|
|
|
const post = Astro.props;
|
2023-09-01 17:38:59 +00:00
|
|
|
const { Content, remarkPluginFrontmatter, headings } = await post.render();
|
2023-09-08 10:10:52 +00:00
|
|
|
const { title, toc, heroImage: heroImagePath, heroAlt, draft } = post.data;
|
2023-08-31 15:33:14 +00:00
|
|
|
|
|
|
|
let heroImage;
|
|
|
|
if (heroImagePath) {
|
|
|
|
heroImage = await getImage({ src: heroImagePath });
|
|
|
|
}
|
2023-08-31 15:37:26 +00:00
|
|
|
const datestamp = post.data.date.toLocaleDateString(undefined, {
|
|
|
|
year: "numeric",
|
|
|
|
month: "short",
|
|
|
|
day: "numeric",
|
|
|
|
});
|
2023-09-02 03:32:18 +00:00
|
|
|
const excerpt = remarkPluginFrontmatter.excerpt?.replaceAll("\n", "");
|
2023-08-31 03:47:22 +00:00
|
|
|
---
|
|
|
|
|
2023-09-02 03:25:11 +00:00
|
|
|
<BaseLayout title={title} pad={false} toc={toc}>
|
2023-08-31 15:37:26 +00:00
|
|
|
<meta slot="head" property="og:title" content={post.data.title} />
|
2023-09-01 12:59:21 +00:00
|
|
|
<meta slot="head" property="og:url" content={Astro.url} />
|
2023-09-02 03:25:11 +00:00
|
|
|
<meta slot="head" property="og:description" content={excerpt} />
|
2023-08-31 15:37:26 +00:00
|
|
|
<meta slot="head" property="og:type" content="article" />
|
2023-09-01 12:59:21 +00:00
|
|
|
<meta slot="head" property="og:locale" content="en_US" />
|
2023-09-01 03:45:24 +00:00
|
|
|
{heroImage && <meta slot="head" property="og:image" content={heroImage.src} />}
|
2023-09-01 12:59:21 +00:00
|
|
|
{heroAlt && <meta slot="head" property="og:image:alt" content={heroAlt} />}
|
|
|
|
|
2023-09-01 13:01:19 +00:00
|
|
|
<meta slot="head" property="keywords" content={post.data.tags.join(", ")} />
|
2023-09-02 03:25:11 +00:00
|
|
|
<meta slot="head" property="description" content={excerpt} />
|
2023-08-31 15:37:26 +00:00
|
|
|
<meta slot="head" property="article:published_time" content={datestamp} />
|
2023-09-01 13:02:15 +00:00
|
|
|
<meta slot="head" property="article:author" content="Michael Zhang" />
|
2023-08-31 15:37:26 +00:00
|
|
|
|
2023-09-01 17:38:59 +00:00
|
|
|
<TocWrapper toc={toc} headings={headings}>
|
|
|
|
<div class="post-container">
|
|
|
|
<h1 class="post-title">{post.data.title}</h1>
|
2023-08-31 15:33:14 +00:00
|
|
|
|
2023-09-01 17:38:59 +00:00
|
|
|
<span class="tags">
|
|
|
|
{
|
|
|
|
post.data.draft && (
|
|
|
|
<a href="/drafts" class="tag draft">
|
|
|
|
<i class="fa fa-warning" aria-hidden="true" />
|
|
|
|
<span class="text">draft</span>
|
|
|
|
</a>
|
|
|
|
)
|
|
|
|
}
|
2023-09-01 14:16:36 +00:00
|
|
|
|
2023-09-01 17:38:59 +00:00
|
|
|
{
|
|
|
|
post.data.tags.map((tag) => (
|
|
|
|
<a href={`/tags/${tag}`} class="tag">
|
|
|
|
<i class="fa fa-tag" aria-hidden="true" />
|
|
|
|
<span class="text">{tag}</span>
|
|
|
|
</a>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</span>
|
2023-09-01 14:16:36 +00:00
|
|
|
|
2023-09-01 17:38:59 +00:00
|
|
|
<small class="post-meta">
|
|
|
|
Posted on <Timestamp timestamp={post.data.date} />
|
|
|
|
- {remarkPluginFrontmatter.minutesRead}
|
|
|
|
</small>
|
2023-08-31 08:07:03 +00:00
|
|
|
|
2023-09-01 17:38:59 +00:00
|
|
|
{
|
|
|
|
heroImage && heroAlt && (
|
|
|
|
<div style={`background-image: url(${heroImage.src});`} title={heroAlt} class="hero" />
|
|
|
|
)
|
|
|
|
}
|
2023-08-31 08:07:03 +00:00
|
|
|
|
2023-09-02 01:59:23 +00:00
|
|
|
<div class="post-content" id="post-content">
|
2023-09-01 17:38:59 +00:00
|
|
|
<Content />
|
2023-09-02 03:25:11 +00:00
|
|
|
|
|
|
|
<hr />
|
|
|
|
|
2023-09-08 10:10:52 +00:00
|
|
|
{
|
|
|
|
!draft && (
|
|
|
|
<script
|
|
|
|
src="https://utteranc.es/client.js"
|
|
|
|
repo="iptq/blog-comments"
|
|
|
|
issue-term="og:title"
|
|
|
|
theme="github-light"
|
|
|
|
crossorigin="anonymous"
|
|
|
|
async
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
2023-09-01 17:38:59 +00:00
|
|
|
</div>
|
2023-08-31 15:33:14 +00:00
|
|
|
</div>
|
2023-09-01 17:38:59 +00:00
|
|
|
</TocWrapper>
|
2023-08-31 03:47:22 +00:00
|
|
|
</BaseLayout>
|