0
mirror of https://github.com/valentineus/popov.link.git synced 2025-07-03 16:10:26 +03:00
Files
popov.link/src/pages/blog/[...slug].astro

79 lines
1.7 KiB
Plaintext
Raw Normal View History

2024-09-04 21:16:37 +00:00
---
import { type CollectionEntry, getCollection } from "astro:content";
2024-09-06 08:36:02 +00:00
import Comments from "../../components/Comments.astro";
2024-09-12 16:36:57 +00:00
import Layout from "../../layouts/BaseLayout.astro";
import blogPostSchema from "../../utils/schemas/blogPostSchema";
2024-10-02 23:04:27 +00:00
import dayjs from "dayjs";
2024-09-04 21:16:37 +00:00
2024-09-12 22:57:55 +00:00
type Props = CollectionEntry<"blog">;
2024-09-04 21:16:37 +00:00
export async function getStaticPaths() {
2024-10-02 23:04:27 +00:00
const posts = await getCollection("blog", ({ data }) => {
return data.draft !== true;
});
2024-09-12 16:36:57 +00:00
return posts.map((post) => ({
2024-09-04 21:16:37 +00:00
params: { slug: post.slug },
2024-09-12 16:36:57 +00:00
props: post,
2024-09-04 21:16:37 +00:00
}));
}
2024-09-12 16:36:57 +00:00
const post = Astro.props;
const { Content, remarkPluginFrontmatter } = await post.render();
const description = post.data.description;
const isBasedOn = post.data.basedOn;
const lang = post.data.lang;
const slug = post.slug;
const title = post.data.title;
const dateModified = post.data.dateModified?.toISOString();
const datePublished = post.data.datePublished.toISOString();
const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY");
const schema = blogPostSchema({
siteUrl: new URL("/", Astro.site).toString(),
title,
description,
slug,
datePublished,
dateModified,
lang,
isBasedOn,
});
2024-09-04 21:16:37 +00:00
---
<style lang="scss">
@use "../../scss/variables" as *;
2024-10-02 23:04:27 +00:00
p {
opacity: 0.5;
}
</style>
2024-10-02 23:04:27 +00:00
<Layout title={title} description={description} lang={lang} schema={schema}>
<article>
<header>
<h1>{title}</h1>
<p>
<small>
Posted
<time datetime={datePublished} lang="en">{formattedDate}</time>
<span>&nbsp;•&nbsp;</span>
<span>{remarkPluginFrontmatter.minutesRead}</span>
</small>
</p>
</header>
<section>
<Content />
</section>
<section>
<Comments />
</section>
</article>
2024-09-04 21:16:37 +00:00
</Layout>