From 6ad674de9e67042ff83ad06c7d9146ee574cd470 Mon Sep 17 00:00:00 2001 From: GNQG Date: Sat, 26 Dec 2020 21:13:21 +0900 Subject: [PATCH 1/2] add getScopePageTitle for frontmatter --- src/node/handleOptions.ts | 2 ++ src/node/index.ts | 5 ++++- src/node/interface/Frontmatter.ts | 3 +++ src/node/interface/Options.ts | 2 ++ 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/node/handleOptions.ts b/src/node/handleOptions.ts index c8e821a..45ab5a6 100644 --- a/src/node/handleOptions.ts +++ b/src/node/handleOptions.ts @@ -151,6 +151,7 @@ export function handleOptions( path: indexPath, layout: indexLayout, scopeLayout, + getScopePageTitle, frontmatter, pagination = {} as PaginationConfig, } = frontmatterPage; @@ -183,6 +184,7 @@ export function handleOptions( keys, map, scopeLayout, + getScopePageTitle, _handler: curryFrontmatterHandler(id, map, indexPath), }); } diff --git a/src/node/index.ts b/src/node/index.ts index 2c33875..ef7b843 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -107,6 +107,7 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { pagination, keys, scopeLayout, + getScopePageTitle, } = frontmatterClassifiedPage; return Object.keys(map).map(key => { const { path, scope } = map[key]; @@ -144,7 +145,9 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { scopeLayout, DefaultLayoutEnum.FrontmatterPagination ), - title: `${key} ${entryTitle}`, + title: getScopePageTitle + ? getScopePageTitle(key) + : `${key} ${entryTitle}`, }, }; }); diff --git a/src/node/interface/Frontmatter.ts b/src/node/interface/Frontmatter.ts index 19ca081..6b60263 100644 --- a/src/node/interface/Frontmatter.ts +++ b/src/node/interface/Frontmatter.ts @@ -1,12 +1,15 @@ import { FrontmatterHandler } from '../util'; import { PaginationConfig } from './Pagination'; +export type GetScopePageTitle = (key: string) => string; + export interface FrontmatterClassificationPage { id: string; entryTitle: string; pagination: PaginationConfig; keys: string[]; scopeLayout?: string; + getScopePageTitle?: GetScopePageTitle; map: Record; _handler: FrontmatterHandler; } diff --git a/src/node/interface/Options.ts b/src/node/interface/Options.ts index 2681626..8815730 100644 --- a/src/node/interface/Options.ts +++ b/src/node/interface/Options.ts @@ -2,6 +2,7 @@ * A Directory-based Classifier */ import { PaginationConfig } from './Pagination'; +import { GetScopePageTitle } from './Frontmatter'; export interface DirectoryClassifier { /** @@ -75,6 +76,7 @@ export interface FrontmatterClassifier { * `/tag/vue` will use `Foo.vue` as the layout */ scopeLayout?: string; + getScopePageTitle?: GetScopePageTitle; /** * Frontmatter for index page. */ From b9391a4e0355edbcf789119601a39f7ee6a13324 Mon Sep 17 00:00:00 2001 From: GNQG Date: Sun, 27 Dec 2020 00:25:10 +0900 Subject: [PATCH 2/2] add docs for getScopePageTitle --- docs/config/README.md | 13 +++++++++++++ src/node/interface/Options.ts | 3 +++ 2 files changed, 16 insertions(+) diff --git a/docs/config/README.md b/docs/config/README.md index 60f870b..41ba94f 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -178,6 +178,19 @@ Layout component name for entry page. Layout component name for scope page. +### getScopePageTitle + +- Type: function +- Default: `See Below` + +A function to get the title of scope page dynamically: + +```js +function getScopePageTitle (key) { + return `${key} | Directory title` +} +``` + ### frontmatter - Type: `Record` diff --git a/src/node/interface/Options.ts b/src/node/interface/Options.ts index 8815730..5c03ea5 100644 --- a/src/node/interface/Options.ts +++ b/src/node/interface/Options.ts @@ -76,6 +76,9 @@ export interface FrontmatterClassifier { * `/tag/vue` will use `Foo.vue` as the layout */ scopeLayout?: string; + /** + * A function to get the title of scope page dynamically. + */ getScopePageTitle?: GetScopePageTitle; /** * Frontmatter for index page.