diff options
author | Valentin Popov <valentin@popov.link> | 2025-06-11 19:47:48 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2025-06-11 19:47:48 +0300 |
commit | 78a9c2abc56d47637eaa46eb1ce99b682d7bde0d (patch) | |
tree | 94001d8c984a70f1138f6240da61cf8aa27d20ec /src/components/Sections/LatestPosts.astro | |
parent | 604e507b311171f0f5d914ce28a3d42a2281a5e6 (diff) | |
download | popov.link-78a9c2abc56d47637eaa46eb1ce99b682d7bde0d.tar.xz popov.link-78a9c2abc56d47637eaa46eb1ce99b682d7bde0d.zip |
feat: add LatestPosts section to homepage
- Introduced a new LatestPosts component to display the five most recent blog posts.
- Updated the index page to include the LatestPosts section, enhancing content visibility.
- Made minor text adjustments in the Welcome section for clarity.
Diffstat (limited to 'src/components/Sections/LatestPosts.astro')
-rw-r--r-- | src/components/Sections/LatestPosts.astro | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/components/Sections/LatestPosts.astro b/src/components/Sections/LatestPosts.astro new file mode 100644 index 0000000..04ce9fe --- /dev/null +++ b/src/components/Sections/LatestPosts.astro @@ -0,0 +1,35 @@ +--- +import { getCollection } from "astro:content"; +import dayjs from "dayjs"; + +const posts = await getCollection("blog", ({ data }) => { + return data.draft !== true; +}); + +posts.sort((a, b) => b.data.pubDate.getTime() - a.data.pubDate.getTime()); + +const latestPosts = posts.slice(0, 5); +--- + +<style lang="scss"> + @use "../../scss/variables" as *; + + small { + font-size: $fontSizeBase * 0.75; + opacity: 0.5; + } +</style> + +<section> + <h2>Latest posts</h2> + <ul> + { + latestPosts.map((post) => ( + <li> + <a href={`/blog/${post.slug}`}>{post.data.title}</a> + <small>{dayjs(post.data.pubDate.toString()).format("MMMM DD, YYYY")}</small> + </li> + )) + } + </ul> +</section> |