0
mirror of https://github.com/valentineus/popov.link.git synced 2025-07-23 08:38:46 +03:00
Files
popov.link/src/pages/blog/[...slug].astro
Valentin Popov a81117972d feat: implement Open Graph image generation and enhance configuration
- Added ogImages integration to generate Open Graph images for blog posts.
- Updated configuration to include Open Graph settings and default preview image.
- Refactored Head component to utilize new preview property for Open Graph meta tags.
- Enhanced blog post schema to include preview image for structured data representation.
- Introduced utility functions for creating Open Graph images with dynamic content.
2025-06-14 19:25:16 +00:00

81 lines
1.7 KiB
Plaintext

---
import { type CollectionEntry, getCollection } from "astro:content";
import Comments from "../../components/Comments.astro";
import Layout from "../../layouts/BaseLayout.astro";
import blogPostSchema from "../../utils/schemas/blogPostSchema";
import dayjs from "dayjs";
type Props = CollectionEntry<"blog">;
export async function getStaticPaths() {
const posts = await getCollection("blog", ({ data }) => {
return data.draft !== true;
});
return posts.map((post) => ({
params: { slug: post.slug },
props: post,
}));
}
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 preview = `/images/preview/${post.slug}.png`;
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(),
dateModified,
datePublished,
description,
isBasedOn,
lang,
preview,
slug,
title,
});
---
<style lang="scss">
@use "../../scss/variables" as *;
p {
opacity: 0.5;
}
</style>
<Layout title={title} description={description} preview={preview} 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>
</Layout>