blog/src/components/PostList.astro

71 lines
1.5 KiB
Plaintext
Raw Normal View History

2023-08-31 03:47:22 +00:00
---
2023-08-31 08:07:03 +00:00
import { getCollection, type CollectionEntry } from "astro:content";
import Timestamp from "./Timestamp.astro";
import { sortBy } from "lodash-es";
interface Props {
basePath: string;
includeDrafts?: boolean;
}
type Post = CollectionEntry<"posts">;
const { basePath, includeDrafts } = Astro.props;
const filter = includeDrafts ? (_: Post) => true : (post: Post) => !post.data.draft;
const allPosts = await getCollection("posts", filter);
const sortedPosts = sortBy(allPosts, (post) => -post.data.date);
2023-08-31 03:47:22 +00:00
---
2023-08-31 08:07:03 +00:00
<table class="postListing">
2023-08-31 03:47:22 +00:00
{
2023-08-31 08:07:03 +00:00
sortedPosts.map((post) => {
2023-08-31 03:47:22 +00:00
return (
2023-08-31 08:07:03 +00:00
<tr class="row">
<td class="info">
<Timestamp timestamp={post.data.date} />
</td>
2023-08-31 03:47:22 +00:00
<td>
<span class="title">
2023-08-31 08:07:03 +00:00
<a href={`${basePath}/${post.slug}`} class="brand-colorlink">
2023-08-31 03:47:22 +00:00
{post.data.title}
</a>
</span>
</td>
</tr>
);
})
}
</table>
2023-08-31 08:07:03 +00:00
<style lang="scss">
.postListing {
width: 100%;
border-spacing: 6px;
td {
// padding-bottom: 10px;
// line-height: 1;
.title {
font-size: 1.1em;
}
.summary {
padding-top: 4px;
font-size: 0.64em;
color: var(--smaller-text-color);
p {
display: inline;
}
}
}
td.info {
color: var(--smaller-text-color);
font-size: 0.75em;
white-space: nowrap;
text-align: right;
}
}
</style>