Skip to content

Commit

Permalink
fix: ensure using the same markdown config when extracting headers
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 18, 2018
1 parent 24a8fe5 commit 14d4d25
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
14 changes: 10 additions & 4 deletions lib/prepare.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down Expand Up @@ -120,7 +121,8 @@ async function resolveOptions (sourceDir) {
pagesData: null,
themePath: null,
notFoundPath: null,
useDefaultTheme
useDefaultTheme,
markdown: createMarkdown(siteConfig)
}

if (useDefaultTheme) {
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions lib/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/webpack/createBaseConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lib/webpack/markdownLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 14d4d25

Please sign in to comment.