Replace local functions with getSortedPosts function

This commit is contained in:
Sat Naing
2022-09-10 16:23:06 +06:30
parent a0d850c130
commit 92c0ed3a71
2 changed files with 4 additions and 10 deletions
+2 -5
View File
@@ -4,6 +4,7 @@ import Header from "@components/Header.astro";
import Card from "@components/Card.astro"; import Card from "@components/Card.astro";
import Footer from "@components/Footer.astro"; import Footer from "@components/Footer.astro";
import LinkButton from "@components/LinkButton.astro"; import LinkButton from "@components/LinkButton.astro";
import getSortedPosts from "src/utils/getSortedPosts";
export interface Frontmatter { export interface Frontmatter {
title: string; title: string;
@@ -17,11 +18,7 @@ export interface Frontmatter {
const posts = await Astro.glob<Frontmatter>("../pages/posts/*.md"); const posts = await Astro.glob<Frontmatter>("../pages/posts/*.md");
const sortedPosts = posts.sort( const sortedPosts = getSortedPosts(posts);
(a, b) =>
Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) -
Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000)
);
--- ---
<Layout title="Welcome to Astro."> <Layout title="Welcome to Astro.">
+2 -5
View File
@@ -5,14 +5,11 @@ import Footer from "@components/Footer.astro";
import Main from "@layouts/Main.astro"; import Main from "@layouts/Main.astro";
import Card from "@components/Card.astro"; import Card from "@components/Card.astro";
import type { Frontmatter } from "../index.astro"; import type { Frontmatter } from "../index.astro";
import getSortedPosts from "src/utils/getSortedPosts";
const posts = await Astro.glob<Frontmatter>("./*.md"); const posts = await Astro.glob<Frontmatter>("./*.md");
const sortedPosts = posts.sort( const sortedPosts = getSortedPosts(posts);
(a, b) =>
Math.floor(new Date(b.frontmatter.datetime).getTime() / 1000) -
Math.floor(new Date(a.frontmatter.datetime).getTime() / 1000)
);
--- ---
<Layout title="Welcome to Astro."> <Layout title="Welcome to Astro.">