diff --git a/src/components/BlogItem.astro b/src/components/BlogItem.astro index 1535621..0f49f9c 100644 --- a/src/components/BlogItem.astro +++ b/src/components/BlogItem.astro @@ -1,17 +1,35 @@ --- import TerminalBorder from "../components/TerminalBorder.astro"; +function formatDate(date: Date) { + const day = date.getDate(); + const month = date.toLocaleString("default", { month: "long" }); + const year = date.getFullYear(); + + let suffix = "th"; + if (day === 1 || day === 21 || day === 31) { + suffix = "st"; + } else if (day === 2 || day === 22) { + suffix = "nd"; + } else if (day === 3 || day === 23) { + suffix = "rd"; + } + + return `${month} ${day}${suffix} ${year}`; +} + interface Props { title: string; description: string; - date: string; + date: Date; href: string; + header?: string; } -const { title, description, date, href } = Astro.props; +const { title, description, date, href, header } = Astro.props; --- - +

diff --git a/src/pages/blogs.astro b/src/pages/blogs.astro index c571090..128210c 100644 --- a/src/pages/blogs.astro +++ b/src/pages/blogs.astro @@ -4,29 +4,12 @@ import TerminalBorder from "../components/TerminalBorder.astro"; import BlogItem from "../components/BlogItem.astro"; import { getCollection } from "astro:content"; -function formatDate(date: Date) { - const day = date.getDate(); - const month = date.toLocaleString("default", { month: "long" }); - const year = date.getFullYear(); - - let suffix = "th"; - if (day === 1 || day === 21 || day === 31) { - suffix = "st"; - } else if (day === 2 || day === 22) { - suffix = "nd"; - } else if (day === 3 || day === 23) { - suffix = "rd"; - } - - return `${month} ${day}${suffix} ${year}`; -} - const blogs = (await getCollection("blogs")) .sort((a, b) => +new Date(b.data.date) - +new Date(a.data.date)) .map((blog) => ({ title: blog.data.title, description: blog.data.description, - date: formatDate(blog.data.date), + date: blog.data.date, href: "/blogs/" + blog.slug, })); --- diff --git a/src/pages/index.astro b/src/pages/index.astro index dc73f9c..6a353e2 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -1,7 +1,14 @@ --- +import { getCollection } from "astro:content"; import Terminal from "../layouts/Terminal.astro"; import TerminalBorder from "../components/TerminalBorder.astro"; import Link from "../components/Link.astro"; +import BlogItem from "../components/BlogItem.astro"; + +const latestBlog = (await getCollection("blogs")).reduce((latest, blog) => { + const blogDate = new Date(blog.data.date); + return blogDate > new Date(latest.data.date) ? blog : latest; +}); const sshKey = `ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO7P9K9D5RkBk+JCRRS6AtHuTAc6cRpXfRfRMg/Kyren`; const fingerprint = ` @@ -108,17 +115,13 @@ watching Anime or solving Rubik's cubes fast.`.trimStart();

{aboutMe}

- -

- github.com/Kyren223 -
- discord.com/Kyren223 -

-
+