From 14d4d2581f4b7c71ea71a41a1849f582090edb97 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 17 Apr 2018 23:19:28 -0400 Subject: [PATCH] fix: ensure using the same markdown config when extracting headers --- lib/prepare.js | 14 ++++++++++---- lib/util/index.js | 3 +-- lib/webpack/createBaseConfig.js | 4 ++-- lib/webpack/markdownLoader.js | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/prepare.js b/lib/prepare.js index 2c29b737..acd7e82f 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -1,8 +1,9 @@ -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 } diff --git a/lib/util/index.js b/lib/util/index.js index d6ac59f3..0545fe0f 100644 --- a/lib/util/index.js +++ b/lib/util/index.js @@ -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) { diff --git a/lib/webpack/createBaseConfig.js b/lib/webpack/createBaseConfig.js index 36d042fc..70cb6d5d 100644 --- a/lib/webpack/createBaseConfig.js +++ b/lib/webpack/createBaseConfig.js @@ -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') diff --git a/lib/webpack/markdownLoader.js b/lib/webpack/markdownLoader.js index f73f7b74..a6f2c3d2 100644 --- a/lib/webpack/markdownLoader.js +++ b/lib/webpack/markdownLoader.js @@ -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 -- GitLab