提交 14d4d258 编写于 作者: E Evan You

fix: ensure using the same markdown config when extracting headers

上级 24a8fe59
const fs = require('fs-extra')
const path = require('path')
const fs = require('fs-extra')
const globby = require('globby')
const yaml = require('yaml-front-matter')
const yamlParser = require('js-yaml')
const yaml = require('yaml-front-matter')
const createMarkdown = require('./markdown')
const tempPath = path.resolve(__dirname, 'app/.temp')
const { inferTitle, extractHeaders } = require('./util')
......@@ -120,7 +121,8 @@ async function resolveOptions (sourceDir) {
pagesData: null,
themePath: null,
notFoundPath: null,
useDefaultTheme
useDefaultTheme,
markdown: createMarkdown(siteConfig)
}
if (useDefaultTheme) {
......@@ -171,7 +173,11 @@ async function resolveOptions (sourceDir) {
if (title) {
data.title = title
}
const headers = extractHeaders(frontmatter.__content, ['h2', 'h3'])
const headers = extractHeaders(
frontmatter.__content,
['h2', 'h3'],
options.markdown
)
if (headers.length) {
data.headers = headers
}
......
......@@ -45,9 +45,8 @@ exports.parseFrontmatter = content => {
const LRU = require('lru-cache')
const cache = LRU({ max: 1000 })
const md = require('../markdown')()
exports.extractHeaders = (content, include = []) => {
exports.extractHeaders = (content, include = [], md) => {
const key = content + include.join(',')
const hit = cache.get(key)
if (hit) {
......
......@@ -6,9 +6,9 @@ module.exports = function createBaseConfig ({
outDir,
publicPath,
themePath,
notFoundPath
notFoundPath,
markdown
}, { debug } = {}, isServer) {
const markdown = require('../markdown')(siteConfig)
const Config = require('webpack-chain')
const { VueLoaderPlugin } = require('vue-loader')
const CSSExtractPlugin = require('mini-css-extract-plugin')
......
......@@ -30,7 +30,7 @@ module.exports = function (src) {
if (!isProd && !isServer) {
const inferredTitle = inferTitle(frontmatter)
const headers = extractHeaders(content, ['h2', 'h3'])
const headers = extractHeaders(content, ['h2', 'h3'], markdown)
delete frontmatter.__content
// diff frontmatter and title, since they are not going to be part of the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册