mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-15 12:11:01 +08:00
refactor: update for new content collection api
This commit is contained in:
+10
-12
@@ -1,22 +1,20 @@
|
||||
---
|
||||
import { getCollection } from "astro:content";
|
||||
import Layout from "@layouts/Layout.astro";
|
||||
import Header from "@components/Header.astro";
|
||||
import Footer from "@components/Footer.astro";
|
||||
import LinkButton from "@components/LinkButton.astro";
|
||||
import Hr from "@components/Hr.astro";
|
||||
import Card from "@components/Card";
|
||||
import Socials from "@components/Socials.astro";
|
||||
import getSortedPosts from "@utils/getSortedPosts";
|
||||
import slugify from "@utils/slugify";
|
||||
import type { Frontmatter } from "src/types";
|
||||
import Socials from "@components/Socials.astro";
|
||||
import { SOCIALS } from "@config";
|
||||
|
||||
const posts = await Astro.glob<Frontmatter>("../contents/**/*.md");
|
||||
const posts = await getCollection("blog");
|
||||
|
||||
const sortedPosts = getSortedPosts(posts);
|
||||
const featuredPosts = sortedPosts.filter(
|
||||
({ frontmatter }) => frontmatter.featured
|
||||
);
|
||||
const featuredPosts = sortedPosts.filter(({ data }) => data.featured);
|
||||
|
||||
const socialCount = SOCIALS.filter(social => social.active).length;
|
||||
---
|
||||
@@ -76,10 +74,10 @@ const socialCount = SOCIALS.filter(social => social.active).length;
|
||||
<section id="featured">
|
||||
<h2>Featured</h2>
|
||||
<ul>
|
||||
{featuredPosts.map(({ frontmatter }) => (
|
||||
{featuredPosts.map(({ data }) => (
|
||||
<Card
|
||||
href={`/posts/${slugify(frontmatter)}`}
|
||||
post={frontmatter}
|
||||
href={`/posts/${slugify(data)}`}
|
||||
frontmatter={data}
|
||||
secHeading={false}
|
||||
/>
|
||||
))}
|
||||
@@ -95,11 +93,11 @@ const socialCount = SOCIALS.filter(social => social.active).length;
|
||||
<ul>
|
||||
{
|
||||
sortedPosts.map(
|
||||
({ frontmatter }, index) =>
|
||||
({ data }, index) =>
|
||||
index < 4 && (
|
||||
<Card
|
||||
href={`/posts/${slugify(frontmatter)}`}
|
||||
post={frontmatter}
|
||||
href={`/posts/${slugify(data)}`}
|
||||
frontmatter={data}
|
||||
secHeading={false}
|
||||
/>
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user