Skip to content

Commit

Permalink
feat($plugin-blog): correct Layout for index page and one-level page
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Sep 8, 2018
1 parent 20d612c commit 078696e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions packages/@vuepress/plugin-blog/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const path = require('path')

module.exports = (options, ctx) => ({
extendPageData (pageCtx) {
const {
Expand All @@ -16,15 +18,24 @@ module.exports = (options, ctx) => ({
const isLayoutExists = name => layoutComponentMap[name] !== undefined
const getLayout = name => isLayoutExists(name) ? name : 'Layout'

const isDirectChild = regularPath => path.parse(regularPath).dir === '/'
const enhancers = [
{
when: ({ regularPath }) => regularPath === '/category/',
when: ({ regularPath }) => isDirectChild(regularPath),
frontmatter: { layout: getLayout('Page') }
},
{
when: ({ regularPath }) => regularPath === '/category.html',
frontmatter: { layout: getLayout('Category') }
},
{
when: ({ regularPath }) => regularPath === '/tags/',
when: ({ regularPath }) => regularPath === '/tags.html',
frontmatter: { layout: getLayout('Tag') }
},
{
when: ({ regularPath }) => regularPath === '/',
frontmatter: { layout: getLayout('Layout') }
},
{
when: ({ regularPath }) => regularPath.startsWith('/_posts/'),
frontmatter: {
Expand Down
2 changes: 1 addition & 1 deletion packages/@vuepress/plugin-blog/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vuepress/plugin-blog",
"version": "1.0.0",
"description": "theme plugin for vuepress",
"description": "blog plugin for vuepress",
"main": "index.js",
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 078696e

Please sign in to comment.