Skip to content

Commit 1acb14d

Browse files
committed
feat: expose preprocessHead
1 parent d2c1d5f commit 1acb14d

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

src/markdown.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { componentPlugin } from '@mdit-vue/plugin-component'
44
import { frontmatterPlugin } from '@mdit-vue/plugin-frontmatter'
55
import type { TransformResult } from 'vite'
66
import type { MarkdownEnv, ResolvedOptions } from './types'
7+
import { preprocessHead } from './head'
78

89
const scriptSetupRE = /<\s*script([^>]*)\bsetup\b([^>]*)>([\s\S]*)<\/script>/mg
910
const defineExposeRE = /defineExpose\s*\(/mg
@@ -117,7 +118,7 @@ export function createMarkdown(options: ResolvedOptions) {
117118
data.excerpt = excerpt
118119
}
119120

120-
const { head, frontmatter } = frontmatterPreprocess(data || {}, options)
121+
const { head, frontmatter } = frontmatterPreprocess(data || {}, options, preprocessHead)
121122

122123
if (options.excerpt && !excerptKeyOverlapping && frontmatter.excerpt !== undefined)
123124
delete frontmatter.excerpt

src/options.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { toArray } from '@antfu/utils'
2-
import { preprocessHead } from './head'
3-
import type { Frontmatter, Options, ResolvedOptions } from './types'
2+
import type { Options, ResolvedOptions } from './types'
43
import { getVueVersion } from './utils'
54

65
export function resolveOptions(userOptions: Options): ResolvedOptions {
7-
const defaultOptions: Omit<ResolvedOptions, 'frontmatterPreprocess'> = {
6+
const defaultOptions: ResolvedOptions = {
87
headEnabled: false,
98
headField: '',
109
frontmatter: true,
@@ -24,17 +23,18 @@ export function resolveOptions(userOptions: Options): ResolvedOptions {
2423
wrapperClasses: 'markdown-body',
2524
include: null,
2625
exclude: null,
27-
}
28-
const options = userOptions.frontmatterPreprocess
29-
? { ...defaultOptions, ...userOptions }
30-
: {
31-
...defaultOptions,
32-
...userOptions,
33-
frontmatterPreprocess: (frontmatter: Frontmatter, options: ResolvedOptions) => {
34-
const head = preprocessHead(frontmatter, options)
35-
return { head, frontmatter }
36-
},
26+
frontmatterPreprocess: (frontmatter, options, defaults) => {
27+
return {
28+
head: defaults(frontmatter, options),
29+
frontmatter,
3730
}
31+
},
32+
}
33+
34+
const options = {
35+
...defaultOptions,
36+
...userOptions,
37+
}
3838

3939
options.wrapperClasses = toArray(options.wrapperClasses)
4040
.filter((i?: string) => i)

src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ComponentPluginOptions } from '@mdit-vue/plugin-component'
33
import type { FrontmatterPluginOptions } from '@mdit-vue/plugin-frontmatter'
44
import type { MarkdownItEnv } from '@mdit-vue/types'
55
import type { FilterPattern } from '@rollup/pluginutils'
6+
import type { preprocessHead } from './head'
67

78
/** a `<meta />` property in HTML is defined with the following name/values */
89
export interface MetaProperty {
@@ -106,7 +107,8 @@ export interface Options {
106107
*/
107108
frontmatterPreprocess?: (
108109
frontmatter: Frontmatter,
109-
options: ResolvedOptions
110+
options: ResolvedOptions,
111+
defaultHeadProcess: typeof preprocessHead,
110112
) => {
111113
head: Record<string, any>
112114
frontmatter: Frontmatter

0 commit comments

Comments
 (0)