fix: revert the raw method in post for searching.

This commit is contained in:
Yufan Sheng 2024-11-15 12:59:45 +08:00
parent df50e5897b
commit 5036d1145c
Signed by: syhily
GPG Key ID: 9D18A22A7DCD5A9B

View File

@ -1,6 +1,6 @@
import { defaultCover } from '@/content/config.ts'; import { defaultCover } from '@/content/config.ts';
import options from '@/options'; import options from '@/options';
import { getCollection, type Render } from 'astro:content'; import { getCollection, getEntry, type Render } from 'astro:content';
// Import the collections from the astro content. // Import the collections from the astro content.
const categoriesCollection = await getCollection('categories'); const categoriesCollection = await getCollection('categories');
@ -24,6 +24,7 @@ export type Post = (typeof postsCollection)[number]['data'] & {
slug: string; slug: string;
permalink: string; permalink: string;
render: () => Render['.mdx']; render: () => Render['.mdx'];
raw: () => Promise<string>;
}; };
export type Tag = (typeof tagsCollection)[number]['data'][number] & { counts: number; permalink: string }; export type Tag = (typeof tagsCollection)[number]['data'][number] & { counts: number; permalink: string };
@ -44,6 +45,10 @@ export const posts: Post[] = postsCollection
slug: post.slug, slug: post.slug,
permalink: `/posts/${post.slug}`, permalink: `/posts/${post.slug}`,
render: post.render, render: post.render,
raw: async () => {
const entry = await getEntry('posts', post.slug);
return entry.body;
},
...post.data, ...post.data,
})) }))
.sort((left: Post, right: Post) => { .sort((left: Post, right: Post) => {