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