lib: remove source field from Post interface, use gray-matter for reading time only

This commit is contained in:
2026-06-02 01:08:16 -05:00
parent 575b485c41
commit 98d1541f1b

View File

@@ -16,9 +16,7 @@ export interface PostMeta {
readingTime: number
}
export interface Post extends PostMeta {
source: string // raw MDX string, NOT compiled
}
export interface Post extends PostMeta {}
const getMdxFiles = cache(async () => {
try {
@@ -64,9 +62,10 @@ export const getPost = async (slug: string): Promise<Post | null> => {
const filePath = path.join(postsDirectory, file)
const raw = await fs.promises.readFile(filePath, 'utf8')
const { data, content } = matter(raw)
const { data } = matter(raw)
const readingTime = Math.max(1, Math.ceil(content.split(/\s+/).length / 200))
const contentForReadingTime = raw.replace(/^---[\s\S]*?---\s*?/, '')
const readingTime = Math.max(1, Math.ceil(contentForReadingTime.split(/\s+/).filter(Boolean).length / 200))
return {
slug,
@@ -76,7 +75,6 @@ export const getPost = async (slug: string): Promise<Post | null> => {
tags: data.tags ?? [],
author: data.author ?? null,
coverImage: data.coverImage ?? null,
source: content,
readingTime,
} satisfies Post
}