refactor: update for new content collection api

This commit is contained in:
satnaing
2023-01-28 01:23:37 +06:30
parent 38761e2e8f
commit e8171d327e
4 changed files with 28 additions and 36 deletions
+10 -12
View File
@@ -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}
/>
)