use collections and provide rss feed for the blog

This commit is contained in:
2024-07-22 19:37:18 +02:00
parent 0bca511144
commit 3cc883d082
13 changed files with 1876 additions and 1486 deletions
+24 -18
View File
@@ -1,24 +1,32 @@
---
import {getCollection} from "astro:content";
import BaseLayout from '../../layouts/BaseLayout.astro';
import Bio from '../../components/Bio.astro';
import getPostData from '../../utils/getPostData';
import readingTime from 'reading-time';
import { marked } from 'marked';
export async function getStaticPaths() {
let posts = [];
try {
posts = await Astro.glob('../../data/blog-posts/*.md');
} catch (error) {
console.error("No blog posts found");
}
const posts = await getCollection('posts');
return posts.map(p => ({
params: { slug: p.file.split('/').pop().split('.').shift() },
props: { post: p },
params: {
slug: p.slug
},
props: {
title: p.data.title,
publishDate: p.data.publishDate,
slug: p.slug,
tags: "test",
content: marked.parse(p.body),
readingTime: readingTime(p.body).text,
}
}));
}
const { Content, frontmatter } = Astro.props.post;
const { title, description, publishDate, tags } = frontmatter;
const { slug, readingTime } = getPostData(Astro.props.post);
const { slug, title, description, publishDate, tags, content, readingTime } = Astro.props;
const props = Astro.props;
const permalink = `${Astro.site.href}blog/${slug}`;
---
@@ -27,16 +35,14 @@ const permalink = `${Astro.site.href}blog/${slug}`;
<p>{publishDate} ~ {readingTime}</p>
<h1>{title}</h1>
<div class="tags" style="justify-content: center">
{tags.map(item => (
<span class="tag">{item}</span>
))}
<!--{tags.map(item => (-->
<!-- <span class="tag">{item}</span>-->
<!--))}-->
</div>
<hr />
</header>
<div class="container">
<article class="content">
<Content />
</article>
<article class="content" set:html={content}></article>
<hr />
<Bio />
</div>