Skip to content
This repository has been archived by the owner on May 13, 2024. It is now read-only.

add getScopePageTitle for frontmatters' option #91

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions docs/config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>`
Expand Down
2 changes: 2 additions & 0 deletions src/node/handleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function handleOptions(
path: indexPath,
layout: indexLayout,
scopeLayout,
getScopePageTitle,
frontmatter,
pagination = {} as PaginationConfig,
} = frontmatterPage;
Expand Down Expand Up @@ -183,6 +184,7 @@ export function handleOptions(
keys,
map,
scopeLayout,
getScopePageTitle,
_handler: curryFrontmatterHandler(id, map, indexPath),
});
}
Expand Down
5 changes: 4 additions & 1 deletion src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -144,7 +145,9 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => {
scopeLayout,
DefaultLayoutEnum.FrontmatterPagination
),
title: `${key} ${entryTitle}`,
title: getScopePageTitle
? getScopePageTitle(key)
: `${key} ${entryTitle}`,
},
};
});
Expand Down
3 changes: 3 additions & 0 deletions src/node/interface/Frontmatter.ts
Original file line number Diff line number Diff line change
@@ -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<string, any>;
_handler: FrontmatterHandler;
}
5 changes: 5 additions & 0 deletions src/node/interface/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* A Directory-based Classifier
*/
import { PaginationConfig } from './Pagination';
import { GetScopePageTitle } from './Frontmatter';

export interface DirectoryClassifier {
/**
Expand Down Expand Up @@ -75,6 +76,10 @@ 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.
*/
Expand Down