diff --git a/lib/posts.ts b/lib/posts.ts index 82a563d..5d6ef53 100644 --- a/lib/posts.ts +++ b/lib/posts.ts @@ -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 => { 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 => { tags: data.tags ?? [], author: data.author ?? null, coverImage: data.coverImage ?? null, - source: content, readingTime, } satisfies Post }