From 3918b573227468f8f63618285ed0308f46aed5c8 Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Sat, 10 Sep 2022 01:12:25 +0630 Subject: [PATCH] Add recent section --- src/pages/index.astro | 51 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/src/pages/index.astro b/src/pages/index.astro index 94901b9..0d96ada 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -14,6 +14,12 @@ export interface Frontmatter { } const posts = await Astro.glob("../pages/posts/*.md"); + +const sortedPosts = posts.sort( + (a, b) => + Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) - + Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000) +); --- @@ -83,6 +89,34 @@ const posts = await Astro.glob("../pages/posts/*.md"); } + +
+

Recent

+
    + { + sortedPosts.map( + (post, index) => + index < 4 && ( + + ) + ) + } +
+ +
@@ -113,11 +147,20 @@ const posts = await Astro.glob("../pages/posts/*.md"); @apply w-6 h-6 fill-skin-base hover:fill-skin-accent scale-125 sm:scale-110; } - /* ===== Featured Section ===== */ - #featured-section { - @apply py-10; + /* ===== Featured & Recent Posts Sections ===== */ + #featured-section, + #recent-section { + @apply py-6; } - #featured-section h2 { + #featured-section h2, + #recent-section h2 { @apply font-semibold text-2xl tracking-wide; } + + .all-posts-btn-wrapper { + @apply text-center my-8; + } + .all-posts-btn-wrapper svg { + @apply inline-block w-6 h-6; + }