mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 11:29:33 +08:00
refactor: update collection type and new schema property name
This commit is contained in:
@@ -4,19 +4,22 @@ import Header from "@components/Header.astro";
|
|||||||
import Footer from "@components/Footer.astro";
|
import Footer from "@components/Footer.astro";
|
||||||
import Tag from "@components/Tag.astro";
|
import Tag from "@components/Tag.astro";
|
||||||
import Datetime from "@components/Datetime";
|
import Datetime from "@components/Datetime";
|
||||||
import type { MarkdownInstance } from "astro";
|
import type { CollectionEntry } from "astro:content";
|
||||||
import type { Frontmatter } from "src/types";
|
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
post: MarkdownInstance<Frontmatter>;
|
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)
|
const { Content } = await post.render();
|
||||||
.href;
|
|
||||||
|
const ogUrl = new URL(
|
||||||
|
ogImage?.src ? ogImage?.src : `${title}.svg`,
|
||||||
|
Astro.url.origin
|
||||||
|
).href;
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title={title} author={author} description={description} ogImage={ogUrl}>
|
<Layout title={title} author={author} description={description} ogImage={ogUrl}>
|
||||||
@@ -35,7 +38,7 @@ const ogUrl = new URL(ogImage ? ogImage : `${title}.svg`, Astro.url.origin)
|
|||||||
</div>
|
</div>
|
||||||
<main id="main-content">
|
<main id="main-content">
|
||||||
<h1 class="post-title">{title}</h1>
|
<h1 class="post-title">{title}</h1>
|
||||||
<Datetime datetime={datetime} size="lg" className="my-2" />
|
<Datetime datetime={pubDatetime} size="lg" className="my-2" />
|
||||||
<article id="article" role="article" class="mx-auto max-w-3xl mt-8 prose">
|
<article id="article" role="article" class="mx-auto max-w-3xl mt-8 prose">
|
||||||
<Content />
|
<Content />
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
---
|
---
|
||||||
import { SITE } from "src/config";
|
import { SITE } from "@config";
|
||||||
import Layout from "@layouts/Layout.astro";
|
import Layout from "@layouts/Layout.astro";
|
||||||
import Main from "@layouts/Main.astro";
|
import Main from "@layouts/Main.astro";
|
||||||
import Header from "@components/Header.astro";
|
import Header from "@components/Header.astro";
|
||||||
@@ -7,13 +7,12 @@ import Footer from "@components/Footer.astro";
|
|||||||
import Card from "@components/Card";
|
import Card from "@components/Card";
|
||||||
import LinkButton from "@components/LinkButton.astro";
|
import LinkButton from "@components/LinkButton.astro";
|
||||||
import slugify from "@utils/slugify";
|
import slugify from "@utils/slugify";
|
||||||
import type { MarkdownInstance } from "astro";
|
import type { CollectionEntry } from "astro:content";
|
||||||
import type { Frontmatter } from "src/types";
|
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
pageNum: number;
|
pageNum: number;
|
||||||
totalPages: number;
|
totalPages: number;
|
||||||
posts: MarkdownInstance<Frontmatter>[];
|
posts: CollectionEntry<"blog">[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const { pageNum, totalPages, posts } = Astro.props;
|
const { pageNum, totalPages, posts } = Astro.props;
|
||||||
@@ -27,11 +26,9 @@ const next = pageNum < totalPages ? "" : "disabled";
|
|||||||
<Main pageTitle="Posts" pageDesc="All the articles I've posted.">
|
<Main pageTitle="Posts" pageDesc="All the articles I've posted.">
|
||||||
<ul>
|
<ul>
|
||||||
{
|
{
|
||||||
posts.map(({ frontmatter }) => {
|
posts.map(({ data }) => (
|
||||||
return (
|
<Card href={`/posts/${slugify(data)}`} frontmatter={data} />
|
||||||
<Card href={`/posts/${slugify(frontmatter)}`} post={frontmatter} />
|
))
|
||||||
);
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
</Main>
|
</Main>
|
||||||
|
|||||||
Reference in New Issue
Block a user