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

View File

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