Skip to content

Commit

Permalink
extract PostPreview
Browse files Browse the repository at this point in the history
  • Loading branch information
NobbZ committed Jun 16, 2024
1 parent b1d6f02 commit 8b25aec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 43 deletions.
37 changes: 37 additions & 0 deletions src/components/PostPreview.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
import { getEntry, type CollectionEntry } from "astro:content";
import { postPath, authorPath } from "../scripts/paths";
import Date from "../components/Date.astro";
export interface Props {
post: CollectionEntry<"blog">;
}
const { post } = Astro.props;
const author = await getEntry(post.data.author);
---

<div class:list={["min-h-[150px]", "max-h-[150px]"]}>
<div class:list={["flex", "flex-row", "justify-between"]}>
<h2>
<a href={postPath(post)}>{post.data.title}</a>
</h2>
<div class:list={["flex", "flex-col"]}>
<span class:list={["text-right"]}>
<Date datetime={post.data.date.toISOString()} />
</span>
<span class:list={["text-right"]}>
<a href={authorPath(author)}>
{author.data.first_name}
{author.data.last_name}
</a>
</span>
</div>
</div>
<div>
{/* TODO: provide the hero image */}
{post.data.description}
</div>
</div>
49 changes: 6 additions & 43 deletions src/pages/blog/index.astro
Original file line number Diff line number Diff line change
@@ -1,53 +1,16 @@
---
import { getCollection, getEntry } from "astro:content";
import type { CollectionEntry } from "astro:content";
import { getCollection } from "astro:content";
import PostPreview from "../../components/PostPreview.astro";
import NobbzDev from "../../layouts/NobbzDev.astro";
import Date from "../../components/Date.astro";
import { postPath, authorPath } from "../../scripts/paths";
const blogEntries = await getCollection("blog")
.then((collection) =>
collection.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()),
)
.then(
async (collection) =>
await Promise.all(
collection.map(async (entry) => {
const author = await getEntry(entry.data.author);
return { post: entry, author: author };
}),
),
);
const blogEntries = await getCollection("blog").then((collection) =>
collection.sort((a, b) => b.data.date.getTime() - a.data.date.getTime()),
);
---

<NobbzDev title="Blog">
<ul>
{
blogEntries.map(({ post, author }) => (
<div class:list={["min-h-[150px]", "max-h-[150px]"]}>
<div class:list={["flex", "flex-row", "justify-between"]}>
<h2>
<a href={postPath(post)}>{post.data.title}</a>
</h2>
<div class:list={["flex", "flex-col"]}>
<span class:list={["text-right"]}>
<Date datetime={post.data.date.toISOString()} />
</span>
<span class:list={["text-right"]}>
<a href={authorPath(author)}>
{author.data.first_name} {author.data.last_name}
</a>
</span>
</div>
</div>
<div>
{/* TODO: provide the hero image */}
{post.data.description}
</div>
</div>
))
}
{blogEntries.map((post) => <PostPreview post={post} />)}
</ul>
</NobbzDev>

0 comments on commit 8b25aec

Please sign in to comment.