mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 19:41:02 +08:00
Replace local functions with getSortedPosts function
This commit is contained in:
@@ -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.">
|
||||||
|
|||||||
@@ -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.">
|
||||||
|
|||||||
Reference in New Issue
Block a user