diff --git a/packages/@vuepress/plugin-blog/index.js b/packages/@vuepress/plugin-blog/index.js index bc9ca9d268..931959c75a 100644 --- a/packages/@vuepress/plugin-blog/index.js +++ b/packages/@vuepress/plugin-blog/index.js @@ -1,7 +1,9 @@ +const fs = require("fs") const { path, datatypes: { isString }} = require('@vuepress/shared-utils') module.exports = (options, ctx) => { - const { layoutComponentMap } = ctx + const { layoutComponentMap, sourceDir } = ctx + const componentMap = {} const { pageEnhancers = [], postsDir = '_posts', @@ -11,9 +13,14 @@ module.exports = (options, ctx) => { } = options const isLayoutExists = name => layoutComponentMap[name] !== undefined - const getLayout = (name, fallback) => isLayoutExists(name) ? name : fallback + const componentExists = name => componentMap[name] !== undefined + const getLayout = (name, fallback) => isLayoutExists(name) || componentExists(name) ? name : fallback const isDirectChild = regularPath => path.parse(regularPath).dir === '/' + fs.readdirSync(`${sourceDir}/.vuepress/components/`).forEach(file => { + componentMap[file.split(".")[0]] = file + }) + const enhancers = [ { when: ({ regularPath }) => regularPath === categoryIndexPageUrl,