From 38761e2e8f89da566a89d5d96be8c211e2e366bb Mon Sep 17 00:00:00 2001 From: satnaing Date: Sat, 28 Jan 2023 01:18:25 +0630 Subject: [PATCH] refactor: update collection type and new schema property name --- src/layouts/PostDetails.astro | 19 +++++++++++-------- src/layouts/Posts.astro | 15 ++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/layouts/PostDetails.astro b/src/layouts/PostDetails.astro index f10b9ab..1714dfe 100644 --- a/src/layouts/PostDetails.astro +++ b/src/layouts/PostDetails.astro @@ -4,19 +4,22 @@ import Header from "@components/Header.astro"; import Footer from "@components/Footer.astro"; import Tag from "@components/Tag.astro"; import Datetime from "@components/Datetime"; -import type { MarkdownInstance } from "astro"; -import type { Frontmatter } from "src/types"; +import type { CollectionEntry } from "astro:content"; export interface Props { - post: MarkdownInstance; + post: CollectionEntry<"blog">; } -const { frontmatter, Content } = Astro.props.post; +const { post } = Astro.props; -const { title, author, description, ogImage, datetime, tags } = frontmatter; +const { title, author, description, ogImage, pubDatetime, tags } = post.data; -const ogUrl = new URL(ogImage ? ogImage : `${title}.svg`, Astro.url.origin) - .href; +const { Content } = await post.render(); + +const ogUrl = new URL( + ogImage?.src ? ogImage?.src : `${title}.svg`, + Astro.url.origin +).href; --- @@ -35,7 +38,7 @@ const ogUrl = new URL(ogImage ? ogImage : `${title}.svg`, Astro.url.origin)

{title}

- +
diff --git a/src/layouts/Posts.astro b/src/layouts/Posts.astro index 4a524f7..bd81fe2 100644 --- a/src/layouts/Posts.astro +++ b/src/layouts/Posts.astro @@ -1,5 +1,5 @@ --- -import { SITE } from "src/config"; +import { SITE } from "@config"; import Layout from "@layouts/Layout.astro"; import Main from "@layouts/Main.astro"; import Header from "@components/Header.astro"; @@ -7,13 +7,12 @@ import Footer from "@components/Footer.astro"; import Card from "@components/Card"; import LinkButton from "@components/LinkButton.astro"; import slugify from "@utils/slugify"; -import type { MarkdownInstance } from "astro"; -import type { Frontmatter } from "src/types"; +import type { CollectionEntry } from "astro:content"; export interface Props { pageNum: number; totalPages: number; - posts: MarkdownInstance[]; + posts: CollectionEntry<"blog">[]; } const { pageNum, totalPages, posts } = Astro.props; @@ -27,11 +26,9 @@ const next = pageNum < totalPages ? "" : "disabled";
    { - posts.map(({ frontmatter }) => { - return ( - - ); - }) + posts.map(({ data }) => ( + + )) }