refactor(sitemap): object shorthand

This commit is contained in:
MDLeom 2020-07-01 07:52:00 +01:00
parent a2a68d3291
commit d0de387829
No known key found for this signature in database
GPG Key ID: 5D9DB57A25D34EE3
2 changed files with 14 additions and 20 deletions

View File

@ -13,13 +13,15 @@ const isMatch = (path, patterns) => {
} }
module.exports = function (locals) { module.exports = function (locals) {
const config = this.config const { config } = this
const { sitemap, skip_render } = config
const { path } = sitemap
const skipRenderList = ['*.js', '*.css'] const skipRenderList = ['*.js', '*.css']
if (Array.isArray(config.skip_render)) { if (Array.isArray(skip_render)) {
skipRenderList.push(...config.skip_render) skipRenderList.push(...skip_render)
} else if (config.skip_render != null) { } else if (skip_render != null) {
skipRenderList.push(config.skip_render) skipRenderList.push(skip_render)
} }
const posts = [].concat(locals.posts.toArray(), locals.pages.toArray()) const posts = [].concat(locals.posts.toArray(), locals.pages.toArray())
@ -38,22 +40,15 @@ module.exports = function (locals) {
// configuration dictionary // configuration dictionary
const xmlConfig = { const xmlConfig = {
config: config, config,
posts: posts posts,
tags: locals.tags.toArray()
} }
if (config.sitemap.tags !== false) { const data = template(config).render(xmlConfig)
xmlConfig.tags = locals.tags.toArray()
}
if (config.sitemap.categories !== false) {
xmlConfig.categories = locals.categories.toArray()
}
const xml = template(config).render(xmlConfig)
return { return {
path: config.sitemap.path, path,
data: xml data
} }
} }

View File

@ -9,8 +9,7 @@
const pathFn = require('path') const pathFn = require('path')
const config = hexo.config.sitemap = Object.assign({ const config = hexo.config.sitemap = Object.assign({
path: 'sitemap.xml', path: 'sitemap.xml'
tags: true
}, hexo.config.sitemap) }, hexo.config.sitemap)
if (!pathFn.extname(config.path)) { if (!pathFn.extname(config.path)) {