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()); +--- + + diff --git a/src/layouts/BlogPost.astro b/src/layouts/BlogPost.astro index db3b543..c79c203 100644 --- a/src/layouts/BlogPost.astro +++ b/src/layouts/BlogPost.astro @@ -6,21 +6,59 @@ import FormattedDate from '../components/FormattedDate.astro'; type Props = CollectionEntry<'blog'>['data']; -const { title, description, pubDate } = Astro.props; +const { title, description, pubDate, draft, tags, categories } = Astro.props; +const [category] = categories; ---

{title}

- - +
+

date published:

+

+ category: + + {category} + +

+

+ `${tag}`) + .join(', ')} + /> + { + draft && ( +

+ + This is a draft! Its content is subject to change. + +
+ ) + } +

+ +
-
- + + diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index e784797..331b902 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -1,10 +1,6 @@ --- -import { getCollection } from 'astro:content'; import BaseLayout from '../../layouts/BaseLayout.astro'; - -const posts = (await getCollection('blog', (entry) => !entry.data.draft)).sort( - (a, b) => a.data.pubDate.valueOf() - b.data.pubDate.valueOf() -); +import PostList from '../../components/PostList.astro'; --- !entry.data.draft)).sort( >

My blog

- +