{title}
-date published:
+ category: + + {category} + +
+
+ `${tag}`)
+ .join(', ')}
+ />
+ {
+ draft && (
+
diff --git a/src/components/PostList.astro b/src/components/PostList.astro new file mode 100644 index 0000000..86d6e6b --- /dev/null +++ b/src/components/PostList.astro @@ -0,0 +1,31 @@ +--- +import { CollectionEntry, getCollection } from 'astro:content'; + +export interface Props { + filterFn?: (entry: CollectionEntry<'blog'>) => unknown; +} + +const defaultFilterFn = (entry: CollectionEntry<'blog'>) => true; +const { filterFn = defaultFilterFn } = Astro.props; + +const posts = ( + await getCollection( + 'blog', + (entry) => filterFn(entry) && (import.meta.env.DEV || !entry.data.draft) + ) +).sort((a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf()); +--- + +
No posts were found
+ ) : ( + posts.map((post) => ( +date published:
+ category: + + {category} + +
+
+ `${tag}`)
+ .join(', ')}
+ />
+ {
+ draft && (
+