From 078696e9384590cfd4cad4db89b75bbce38bebed Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Sun, 9 Sep 2018 00:20:31 +0800 Subject: [PATCH] feat($plugin-blog): correct Layout for index page and one-level page --- packages/@vuepress/plugin-blog/index.js | 15 +++++++++++++-- packages/@vuepress/plugin-blog/package.json | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/@vuepress/plugin-blog/index.js b/packages/@vuepress/plugin-blog/index.js index 3e8989a94e..5a6365f9e2 100644 --- a/packages/@vuepress/plugin-blog/index.js +++ b/packages/@vuepress/plugin-blog/index.js @@ -1,3 +1,5 @@ +const path = require('path') + module.exports = (options, ctx) => ({ extendPageData (pageCtx) { const { @@ -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: { diff --git a/packages/@vuepress/plugin-blog/package.json b/packages/@vuepress/plugin-blog/package.json index 2a8cb3aa15..503103e0a0 100644 --- a/packages/@vuepress/plugin-blog/package.json +++ b/packages/@vuepress/plugin-blog/package.json @@ -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"