Skip to content

feat(blog) add component as layout option for Tags/Categories #1139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/@vuepress/plugin-blog/index.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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,
Expand Down