feat: some shit
This commit is contained in:
39
src/pages/blog/[slug].astro
Normal file
39
src/pages/blog/[slug].astro
Normal file
@ -0,0 +1,39 @@
|
||||
---
|
||||
import { getCollection } from "astro:content";
|
||||
import Post from "../../layouts/Post.astro";
|
||||
import { getLocale } from "astro-i18n-aut";
|
||||
import { filterCollection, parseSlug } from "../../i18n/utils";
|
||||
|
||||
const locale = getLocale(Astro.url);
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const pages = await getCollection("blog");
|
||||
|
||||
const paths = pages.map((page) => {
|
||||
const [slug] = parseSlug(page.id);
|
||||
|
||||
return { params: { slug }, props: {...page} };
|
||||
});
|
||||
|
||||
console.log("PATHS");
|
||||
console.log(paths);
|
||||
|
||||
return paths;
|
||||
}
|
||||
|
||||
const pages = await getCollection("blog");
|
||||
const page = filterCollection(pages, locale).find((page) => {
|
||||
const [slug] = parseSlug(page.id);
|
||||
return slug === Astro.params.slug;
|
||||
});
|
||||
const formattedDate = page.data?.date?.toLocaleString(locale);
|
||||
|
||||
const { Content } = await page.render();
|
||||
---
|
||||
|
||||
{locale}
|
||||
{JSON.stringify(Astro.params)}
|
||||
<Post {...page.data}>
|
||||
<p>by {page.data.author} • {formattedDate}</p>
|
||||
<Content />
|
||||
</Post>
|
30
src/pages/blog/index.astro
Normal file
30
src/pages/blog/index.astro
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
const pages = await getCollection('blog');
|
||||
import Layout from '../../layouts/Layout.astro';
|
||||
|
||||
import { getLocale } from "astro-i18n-aut";
|
||||
import { filterCollection } from '../../i18n/utils';
|
||||
|
||||
const locale = getLocale(Astro.url);
|
||||
|
||||
const posts = filterCollection(pages, locale);
|
||||
console.log({posts, locale});
|
||||
---
|
||||
|
||||
<Layout title="Dude">
|
||||
<hr/>
|
||||
{
|
||||
posts.map((post) => (
|
||||
<>
|
||||
<a href={"blog/"+post.slug.split("/")[0]}>
|
||||
{post.data.title}
|
||||
</a><br/>
|
||||
</>
|
||||
))
|
||||
}
|
||||
<hr/>
|
||||
</Layout>
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user