diff --git a/src/pages/index.astro b/src/pages/index.astro index b29b537..8566720 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -4,6 +4,7 @@ import Header from "@components/Header.astro"; import Card from "@components/Card.astro"; import Footer from "@components/Footer.astro"; import LinkButton from "@components/LinkButton.astro"; +import getSortedPosts from "src/utils/getSortedPosts"; export interface Frontmatter { title: string; @@ -17,11 +18,7 @@ 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) -); +const sortedPosts = getSortedPosts(posts); --- diff --git a/src/pages/posts/index.astro b/src/pages/posts/index.astro index d986eb0..76472f6 100644 --- a/src/pages/posts/index.astro +++ b/src/pages/posts/index.astro @@ -5,14 +5,11 @@ import Footer from "@components/Footer.astro"; import Main from "@layouts/Main.astro"; import Card from "@components/Card.astro"; import type { Frontmatter } from "../index.astro"; +import getSortedPosts from "src/utils/getSortedPosts"; const posts = await Astro.glob("./*.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) -); +const sortedPosts = getSortedPosts(posts); ---