From 180d42882b559a9890e6a654ac93fbbec7adb2bd Mon Sep 17 00:00:00 2001 From: Billyyyyy3320 Date: Fri, 11 Oct 2019 17:40:34 +0800 Subject: [PATCH] feat: intergrate sitemap --- docs/config/README.md | 15 +++++++++++++++ examples/blog/.vuepress/config.js | 3 +++ package.json | 3 ++- src/node/index.ts | 13 +++++++++++++ src/node/interface/Options.ts | 3 ++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/docs/config/README.md b/docs/config/README.md index e859a40..63ec824 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -188,3 +188,18 @@ Pagination config for all directories and frontmatters. - Required: `false` Please head to [Pagination Config](../pagination/README.md#config) section to get all available options. + +## sitemap + +- Type: `object` +- Default: `{}` +- Required: `false` + +It will be enabled when `hostname` is provided. e.g. + +```js +{ + hostname: 'https://yourdomain' +} +``` +The 404 page is excluded by default. Further options, please head to [vuepress-plugin-sitemap](https://github.com/ekoeryanto/vuepress-plugin-sitemap#options). diff --git a/examples/blog/.vuepress/config.js b/examples/blog/.vuepress/config.js index 2b4f0ad..a5cdd72 100644 --- a/examples/blog/.vuepress/config.js +++ b/examples/blog/.vuepress/config.js @@ -41,6 +41,9 @@ module.exports = { ], globalPagination: { lengthPerPage: 5 + }, + sitemap: { + hostname: 'https://yourdomain' } }], ], diff --git a/package.json b/package.json index b668dab..67b61a6 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "author": "ULIVZ ", "license": "MIT", "dependencies": { - "vuejs-paginate": "^2.1.0" + "vuejs-paginate": "^2.1.0", + "vuepress-plugin-forked-sitemap": "^0.0.1" }, "devDependencies": { "concurrently": "^4.1.0", diff --git a/src/node/index.ts b/src/node/index.ts index ae87d1e..e6b16ae 100644 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -32,6 +32,17 @@ module.exports = (options: BlogPluginOptions, ctx: VuePressContext) => { paginations, } = handleOptions(options, ctx) + /** + * Leverage other plugins + */ + let plugins + + if (options.sitemap && options.sitemap.hostname) { + const sitemapOptions = { ...options.sitemap, exclude: ['/404.html'] } + // Temporarily use a fork of vuepress-plugin-sitemap. Should switch back when it release the next version. + plugins = [['vuepress-plugin-forked-sitemap', sitemapOptions], ['@vuepress/last-updated']] + } + return { name: 'vuepress-plugin-blog', @@ -195,6 +206,8 @@ export default ${serializePaginations(ctx.serializedPaginations, [ path.resolve(__dirname, '../client/classification.js'), path.resolve(__dirname, '../client/pagination.js'), ], + + plugins } } diff --git a/src/node/interface/Options.ts b/src/node/interface/Options.ts index 12256c8..ec31436 100644 --- a/src/node/interface/Options.ts +++ b/src/node/interface/Options.ts @@ -83,5 +83,6 @@ export interface FrontmatterClassifier { export interface BlogPluginOptions { directories: DirectoryClassifier[]; frontmatters: FrontmatterClassifier[]; - globalPagination: PaginationConfig + globalPagination: PaginationConfig; + sitemap:any }