From 795cdb21079aaa01b0711d384807263341cc11d9 Mon Sep 17 00:00:00 2001 From: Cassidy Williams <1454517+cassidoo@users.noreply.github.com> Date: Wed, 16 Nov 2022 23:10:11 -0600 Subject: [PATCH] Move random posts to most recently 3 posts --- src/components/{RandomPosts.astro => HomePosts.astro} | 11 ++++++++++- src/pages/index.astro | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) rename src/components/{RandomPosts.astro => HomePosts.astro} (55%) diff --git a/src/components/RandomPosts.astro b/src/components/HomePosts.astro similarity index 55% rename from src/components/RandomPosts.astro rename to src/components/HomePosts.astro index 0bc4853..4806e8e 100644 --- a/src/components/RandomPosts.astro +++ b/src/components/HomePosts.astro @@ -3,7 +3,16 @@ import Post from "../components/Post.astro"; const { allPosts } = Astro.props; -let posts = allPosts.sort(() => 0.5 - Math.random()).slice(0, 3); +// TODO: account for recently updated posts, too +let posts = allPosts + .sort( + (a, b) => + new Date(b.frontmatter.added).valueOf() - + new Date(a.frontmatter.added).valueOf() + ) + .slice(0, 3); + +//.sort(() => 0.5 - Math.random()).slice(0, 3); --- diff --git a/src/pages/index.astro b/src/pages/index.astro index 481ef41..46561a9 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -2,7 +2,7 @@ import BaseHead from "../components/BaseHead.astro"; import Header from "../components/Header.astro"; import Footer from "../components/Footer.astro"; -import RandomPosts from "../components/RandomPosts.astro"; +import HomePosts from "../components/HomePosts.astro"; import ColorScript from "../components/ColorScript.astro"; import { SITE_TITLE, SITE_DESCRIPTION } from "../config"; import { Content as About } from "./about.md"; @@ -40,7 +40,7 @@ let tags = [...new Set(getTags)];

Here's a sampler of some posts

- +

View posts by tag