42 lines
1015 B
Plaintext
42 lines
1015 B
Plaintext
---
|
|
import { getCollection, render } from "astro:content";
|
|
import { getLocale } from "astro-i18n-aut";
|
|
import { filterCollection, parseSlug } from "@i18n/utils";
|
|
import MetaTags from "@components/MetaTags.astro";
|
|
import { markdownToText } from "@helpers/markdown";
|
|
|
|
const locale = getLocale(Astro.url);
|
|
|
|
export async function getStaticPaths() {
|
|
const posts = await getCollection("blog");
|
|
|
|
const paths = posts.map((post) => {
|
|
const [slug] = parseSlug(post.id);
|
|
return { params: { slug }, props: { ...post } };
|
|
});
|
|
|
|
return paths;
|
|
}
|
|
|
|
const pages = await getCollection("blog");
|
|
const page = filterCollection(pages, locale).find((page) => {
|
|
const [slug] = parseSlug(page.id);
|
|
return slug === Astro.params.slug;
|
|
});
|
|
|
|
if (!page) {
|
|
return new Response("Not found", {
|
|
status: 404,
|
|
});
|
|
}
|
|
|
|
const { Content } = await render(page);
|
|
---
|
|
|
|
<MetaTags
|
|
title={page.data.title}
|
|
cover={page.data.cover?.src}
|
|
description={page.data.description || markdownToText(page.body).slice(0, 200)}
|
|
/>
|
|
<Content />
|