Skip to content

Commit 338c14a

Browse files
fix: remove md image from blog meta description (#417)
Co-authored-by: Tanner Linsley <[email protected]>
1 parent e1392d3 commit 338c14a

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

content-collections.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const posts = defineCollection({
1616
...post,
1717
slug: post._meta.path,
1818
excerpt: frontMatter.excerpt,
19+
description: frontMatter.data.description,
1920
content,
2021
}
2122
},

src/routes/_libraries/blog.$.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const fetchBlogPost = createServerFn({ method: 'GET' })
3434

3535
return {
3636
title: post.title,
37-
description: post.excerpt,
37+
description: post.description,
3838
published: post.published,
3939
content: post.content,
4040
authors: post.authors,

src/utils/documents.server.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,9 +312,17 @@ export async function fetchRepoFile(
312312
}
313313

314314
export function extractFrontMatter(content: string) {
315-
return graymatter.default(content, {
316-
excerpt: (file: any) => (file.excerpt = createExcerpt(file.content)),
315+
const result = graymatter.default(content, {
316+
excerpt: (file: any) => (file.excerpt = createRichExcerpt(file.content)),
317317
})
318+
319+
return {
320+
...result,
321+
data: {
322+
...result.data,
323+
description: createExcerpt(result.content)
324+
} as { [key: string]: any } & { description: string }
325+
}
318326
}
319327

320328
function createExcerpt(text: string, maxLength = 200) {
@@ -335,6 +343,12 @@ function createExcerpt(text: string, maxLength = 200) {
335343
cleanText = cleanText.slice(0, maxLength).trim() + '...'
336344
}
337345

346+
return cleanText
347+
}
348+
349+
function createRichExcerpt(text: string, maxLength = 200) {
350+
let cleanText = createExcerpt(text, maxLength)
351+
338352
const imageText = extractFirstImage(text)
339353

340354
if (imageText) {

0 commit comments

Comments
 (0)