From e07f92e276592a4318956aaee2467b3db0202d4f Mon Sep 17 00:00:00 2001 From: zhaobc Date: Thu, 5 Dec 2019 11:49:38 +0800 Subject: [PATCH 1/3] feat: Support frontmatters scoped path (#39) --- src/node/handleOptions.ts | 2 +- src/node/index.ts | 2 +- src/node/util.ts | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/node/handleOptions.ts b/src/node/handleOptions.ts index e8fb1f3..ac5df54 100644 --- a/src/node/handleOptions.ts +++ b/src/node/handleOptions.ts @@ -163,7 +163,7 @@ export function handleOptions( keys, map, scopeLayout, - _handler: curryFrontmatterHandler(id, map), + _handler: curryFrontmatterHandler(id, map, indexPath), }) } diff --git a/src/node/index.ts b/src/node/index.ts index 0770bb3..581e8de 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -131,7 +131,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { /** * Register pagination */ - const indexPath = `/${scope}/${key}/` + const indexPath = path ? `${path}${key}` : `/${scope}/${key}/`; paginations.push({ classifierType: ClassifierTypeEnum.Frontmatter, diff --git a/src/node/util.ts b/src/node/util.ts index dca932b..a2bd021 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -14,15 +14,16 @@ export interface FrontmatterTempMap { export function curryFrontmatterHandler( scope: string, map: FrontmatterTempMap, + path: string, ): FrontmatterHandler -export function curryFrontmatterHandler(scope, map) { +export function curryFrontmatterHandler(scope, map, path) { return (key, pageKey) => { if (key) { if (!map[key]) { map[key] = {} map[key].key = key map[key].scope = scope - map[key].path = `/${scope}/${key}/` + map[key].path = path ? `${path}${key}` : `/${scope}/${key}/` map[key].pageKeys = [] } map[key].pageKeys.push(pageKey) From ce7eba9bf4d5b0e9c78b14832be304f81b190ec7 Mon Sep 17 00:00:00 2001 From: FuckDoctors Date: Sat, 7 Dec 2019 20:55:26 +0800 Subject: [PATCH 2/3] fix: frontmatters scopeLayout path --- examples/frontmatter-classifier/.vuepress/config.js | 1 + src/node/index.ts | 2 +- src/node/util.ts | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/frontmatter-classifier/.vuepress/config.js b/examples/frontmatter-classifier/.vuepress/config.js index 0003a98..10d10c8 100644 --- a/examples/frontmatter-classifier/.vuepress/config.js +++ b/examples/frontmatter-classifier/.vuepress/config.js @@ -12,6 +12,7 @@ module.exports = { path: '/tag/', // Layout of the `entry page` layout: 'Tags', + scopeLayout: 'FrontmatterClassifier', }, ], }], diff --git a/src/node/index.ts b/src/node/index.ts index 581e8de..04d8f97 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -131,7 +131,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { /** * Register pagination */ - const indexPath = path ? `${path}${key}` : `/${scope}/${key}/`; + const indexPath = path; paginations.push({ classifierType: ClassifierTypeEnum.Frontmatter, diff --git a/src/node/util.ts b/src/node/util.ts index a2bd021..297e589 100644 --- a/src/node/util.ts +++ b/src/node/util.ts @@ -23,7 +23,7 @@ export function curryFrontmatterHandler(scope, map, path) { map[key] = {} map[key].key = key map[key].scope = scope - map[key].path = path ? `${path}${key}` : `/${scope}/${key}/` + map[key].path = `${path}${key}/` map[key].pageKeys = [] } map[key].pageKeys.push(pageKey) From f66c7fc6e2b6d4d492301ee6211408ccced0fc79 Mon Sep 17 00:00:00 2001 From: Billyyyyy3320 Date: Sat, 7 Dec 2019 21:44:05 +0800 Subject: [PATCH 3/3] refactor: clean code --- src/node/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/node/index.ts b/src/node/index.ts index 04d8f97..5bf5538 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -131,8 +131,6 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { /** * Register pagination */ - const indexPath = path; - paginations.push({ classifierType: ClassifierTypeEnum.Frontmatter, getPaginationPageTitle(index, id, scope) { @@ -142,7 +140,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { ClassifierTypeEnum.Frontmatter, options.globalPagination, pagination, - indexPath, + path, ctx, keys, ),