Skip to content

Commit 14d4d25

Browse files
committed
fix: ensure using the same markdown config when extracting headers
1 parent 24a8fe5 commit 14d4d25

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

lib/prepare.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const fs = require('fs-extra')
21
const path = require('path')
2+
const fs = require('fs-extra')
33
const globby = require('globby')
4-
const yaml = require('yaml-front-matter')
54
const yamlParser = require('js-yaml')
5+
const yaml = require('yaml-front-matter')
6+
const createMarkdown = require('./markdown')
67
const tempPath = path.resolve(__dirname, 'app/.temp')
78
const { inferTitle, extractHeaders } = require('./util')
89

@@ -120,7 +121,8 @@ async function resolveOptions (sourceDir) {
120121
pagesData: null,
121122
themePath: null,
122123
notFoundPath: null,
123-
useDefaultTheme
124+
useDefaultTheme,
125+
markdown: createMarkdown(siteConfig)
124126
}
125127

126128
if (useDefaultTheme) {
@@ -171,7 +173,11 @@ async function resolveOptions (sourceDir) {
171173
if (title) {
172174
data.title = title
173175
}
174-
const headers = extractHeaders(frontmatter.__content, ['h2', 'h3'])
176+
const headers = extractHeaders(
177+
frontmatter.__content,
178+
['h2', 'h3'],
179+
options.markdown
180+
)
175181
if (headers.length) {
176182
data.headers = headers
177183
}

lib/util/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ exports.parseFrontmatter = content => {
4545

4646
const LRU = require('lru-cache')
4747
const cache = LRU({ max: 1000 })
48-
const md = require('../markdown')()
4948

50-
exports.extractHeaders = (content, include = []) => {
49+
exports.extractHeaders = (content, include = [], md) => {
5150
const key = content + include.join(',')
5251
const hit = cache.get(key)
5352
if (hit) {

lib/webpack/createBaseConfig.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ module.exports = function createBaseConfig ({
66
outDir,
77
publicPath,
88
themePath,
9-
notFoundPath
9+
notFoundPath,
10+
markdown
1011
}, { debug } = {}, isServer) {
11-
const markdown = require('../markdown')(siteConfig)
1212
const Config = require('webpack-chain')
1313
const { VueLoaderPlugin } = require('vue-loader')
1414
const CSSExtractPlugin = require('mini-css-extract-plugin')

lib/webpack/markdownLoader.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = function (src) {
3030

3131
if (!isProd && !isServer) {
3232
const inferredTitle = inferTitle(frontmatter)
33-
const headers = extractHeaders(content, ['h2', 'h3'])
33+
const headers = extractHeaders(content, ['h2', 'h3'], markdown)
3434
delete frontmatter.__content
3535

3636
// diff frontmatter and title, since they are not going to be part of the

0 commit comments

Comments
 (0)