mirror of https://gitlab.com/curben/blog
refactor(sitemap): object shorthand
This commit is contained in:
parent
a2a68d3291
commit
d0de387829
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)) {
|
||||||
|
|
Loading…
Reference in New Issue