Create i18n blog posts
Content stored in /src/content/blog/[slug]/<lang>.md TODO: fix missing content in language TODO: main blog page
This commit is contained in:
@ -1,17 +1,31 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
// 1. Generate a new path for every collection entry
|
||||
export async function getStaticPaths() {
|
||||
const blogEntries = await getCollection('blog');
|
||||
console.log(blogEntries)
|
||||
return blogEntries.map(entry => ({
|
||||
params: { slug: entry.slug }, props: { entry },
|
||||
}));
|
||||
}
|
||||
// 2. For your template, you can get the entry directly from the prop
|
||||
const { entry } = Astro.props;
|
||||
const { Content } = await entry.render();
|
||||
import { getBlogPosts } from "../../../content/config";
|
||||
import BlogPost from "../../../layouts/BlogPost.astro";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const pages = await getBlogPosts();
|
||||
|
||||
const paths = pages.map((page) => {
|
||||
return {
|
||||
// @ts-ignore
|
||||
params: { lang: page?.data.language || "en", slug: page.blog_slug },
|
||||
props: page,
|
||||
};
|
||||
});
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
const { lang, slug } = Astro.params;
|
||||
const page = Astro.props;
|
||||
// @ts-ignore
|
||||
const formattedDate = page.data?.date?.toLocaleString(lang);
|
||||
|
||||
const { Content } = await page.render();
|
||||
---
|
||||
<h1>{entry.data.title}</h1>
|
||||
<Content />
|
||||
|
||||
<BlogPost {...page.data} language={lang}>
|
||||
<h1>{page.data.title}</h1>
|
||||
<p>by {page.data.author} • {formattedDate}</p>
|
||||
<Content />
|
||||
</BlogPost>
|
Reference in New Issue
Block a user