mirror of
https://github.com/YouHaveTrouble/youhavetrouble.github.io.git
synced 2026-05-12 06:16:55 +00:00
use collections and provide rss feed for the blog
This commit is contained in:
+24
-18
@@ -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>
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
import BaseLayout from '../../layouts/BaseLayout.astro';
|
||||
|
||||
const title = 'Blog';
|
||||
const description = 'Latest articles.';
|
||||
const description = 'Something that\'s supposed to be thoughts';
|
||||
const permalink = `${Astro.site.href}blog`;
|
||||
let allPosts = [];
|
||||
try {
|
||||
allPosts = await Astro.glob('../../data/blog-posts/*.md');
|
||||
allPosts = await Astro.glob('../../content/posts/*.md');
|
||||
} catch (error) {
|
||||
console.error('No blog posts found');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user