fix: markdown excerpt metadata

This commit is contained in:
DIYgod 2024-01-17 23:24:13 +08:00
parent 292e3cb1ac
commit 4b80b39ddd
No known key found for this signature in database
2 changed files with 8 additions and 3 deletions

View File

@ -107,7 +107,7 @@ export const expandCrossbellNote = async ({
)}`
} else {
if (!expandedNote.metadata.content.summary && !disableAutofill) {
// TODO expandedNote.metadata.content.summary = renderedMetadata.excerpt
expandedNote.metadata.content.summary = renderedMetadata.excerpt
}
}

View File

@ -74,6 +74,9 @@ const rehypePrism = rehypePrismGenerator(refractor)
export const renderPageContent = (content: string, strictMode?: boolean) => {
let hastTree: HashRoot | undefined = undefined
let mdastTree: MdashRoot | undefined = undefined
const file = new VFile(content)
try {
const pipeline = unified()
.use(remarkParse)
@ -175,8 +178,6 @@ export const renderPageContent = (content: string, strictMode?: boolean) => {
passThrough: allowedCustomWrappers,
} as RehypeRawOptions)
const file = new VFile(content)
// markdown abstract syntax tree
mdastTree = pipeline.parse(file)
// hypertext abstract syntax tree
@ -226,12 +227,16 @@ export const renderPageContent = (content: string, strictMode?: boolean) => {
frontMatter: undefined,
images: [],
audio: undefined,
excerpt: undefined,
} as {
frontMatter?: Record<string, any>
images: string[]
audio?: string
excerpt?: string
}
metadata.excerpt = file.data.meta?.description || undefined
if (mdastTree) {
visit(mdastTree, (node, index, parent) => {
if (node.type === "yaml") {