Commit 7ed04be 1 parent 913c07f commit 7ed04be Copy full SHA for 7ed04be
File tree 1 file changed +15
-12
lines changed
1 file changed +15
-12
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
import BaseLayout from " ../../layouts/BaseLayout.astro" ;
3
3
import BlogPostListItem from " ../../components/BlogPostListItem.astro" ;
4
+ import { getCollection } from " astro:content" ;
4
5
5
6
export async function getStaticPaths() {
6
- const allPosts = Object .values (
7
- import .meta .glob (" ../../data/blog/*.md" , { eager: true }),
8
- );
9
-
10
- const uniqueTags = [
11
- ... new Set (allPosts .map ((post : any ) => post .frontmatter .tags ).flat ()),
12
- ];
13
-
7
+ const allPosts = await getCollection (" blog" );
8
+
9
+ // Get all unique tags
10
+ const uniqueTags = [... new Set (allPosts .flatMap (post => post .data .tags ))];
11
+
14
12
return uniqueTags .map ((tag ) => {
15
- const filteredPosts = allPosts .filter ((post : any ) =>
16
- post .frontmatter .tags .includes (tag ),
13
+ const filteredPosts = allPosts .filter ((post ) =>
14
+ post .data .tags .includes (tag )
17
15
);
16
+
18
17
return {
19
18
params: { tag },
20
19
props: { posts: filteredPosts },
@@ -30,8 +29,12 @@ const { posts } = Astro.props;
30
29
<p >Posts tagged with { tag } </p >
31
30
<ul >
32
31
{
33
- posts .map ((post : any ) => (
34
- <BlogPostListItem url = { post .url } title = { post .frontmatter .title } />
32
+ posts .map ((post ) => (
33
+ <BlogPostListItem
34
+ url = { ` /posts/${post .data .slug } ` }
35
+ title = { post .data .title }
36
+ datePublished = { post .data .formattedDate }
37
+ />
35
38
))
36
39
}
37
40
</ul >
You can’t perform that action at this time.
0 commit comments