From 92c0ed3a7183c0d6579967bb78a9e6459d497887 Mon Sep 17 00:00:00 2001 From: Sat Naing Date: Sat, 10 Sep 2022 16:23:06 +0630 Subject: [PATCH] Replace local functions with getSortedPosts function --- src/pages/index.astro | 7 ++----- src/pages/posts/index.astro | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) 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); ---