Skip to content

Commit c1a2a51

Browse files
committed
feat: update
1 parent b411af2 commit c1a2a51

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

src/loaders/markdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ export default defineLoader({
1919
return
2020
}
2121
const data = yaml.parse(match[1])
22-
// keep original body
23-
data.body = content.slice(match[0].length).trim()
24-
vfile.data.original = data
22+
const raw = content.slice(match[0].length).trim()
23+
// keep original content with multiple keys in vfile.data for later use
24+
vfile.data.original = Object.assign(data, { raw, excerpt: raw, plain: raw, html: raw, body: raw, code: raw })
2525
}
2626
})

src/shared/markdown.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ import remarkRemoveComments from '../plugins/remark-remove-comments'
1414

1515
import type { PluggableList } from 'unified'
1616

17-
interface MarkdownBody {
18-
plain: string
19-
excerpt: string
20-
html: string
21-
}
22-
2317
interface MarkdownOptions {
2418
gfm?: boolean
2519
removeComments?: boolean
@@ -30,7 +24,7 @@ interface MarkdownOptions {
3024
}
3125

3226
export const markdown = ({ gfm = true, removeComments = true, flattenImage = true, flattenListItem = true, remarkPlugins, rehypePlugins }: MarkdownOptions = {}) =>
33-
z.string().transform(async (value, ctx): Promise<MarkdownBody> => {
27+
z.string().transform(async (value, ctx) => {
3428
const file = unified().use(remarkParse) // parse markdown content to a syntax tree
3529
if (gfm) file.use(remarkGfm) // support gfm (autolink literals, footnotes, strikethrough, tables, tasklists).
3630
if (removeComments) file.use(remarkRemoveComments) // remove html comments
@@ -45,21 +39,9 @@ export const markdown = ({ gfm = true, removeComments = true, flattenImage = tru
4539
file.use(rehypeStringify) // serialize html syntax tree
4640
try {
4741
const html = await file.process({ value, path: ctx.path[0] as string })
48-
// const replaces = file.data.replaces as Map<string, string>
49-
// // replace links
50-
// if (replaces != null) {
51-
// for (const [url, publicUrl] of replaces.entries()) {
52-
// value = value.replaceAll(url, publicUrl)
53-
// }
54-
// }
55-
return {
56-
// raw: value,
57-
excerpt: html.data.excerpt as string,
58-
plain: html.data.plain as string,
59-
html: html.toString()
60-
}
42+
return html.toString()
6143
} catch (err: any) {
6244
ctx.addIssue({ code: 'custom', message: err.message })
63-
return {} as MarkdownBody
45+
return value
6446
}
6547
})

0 commit comments

Comments
 (0)