2019-05-27 02:08:57 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const pathFn = require('path')
|
|
|
|
const fs = require('fs')
|
2019-06-04 03:38:09 +00:00
|
|
|
let sitemapTmpl = ''
|
2019-05-27 02:08:57 +00:00
|
|
|
|
|
|
|
module.exports = function (config) {
|
|
|
|
if (sitemapTmpl) return sitemapTmpl
|
|
|
|
|
|
|
|
const nunjucks = require('nunjucks')
|
|
|
|
const env = new nunjucks.Environment(null, {
|
|
|
|
autoescape: false,
|
|
|
|
watch: false
|
|
|
|
})
|
|
|
|
|
|
|
|
env.addFilter('uriencode', (str) => {
|
|
|
|
return encodeURI(str)
|
|
|
|
})
|
|
|
|
|
|
|
|
const sitemapSrc = config.sitemap.template || pathFn.join(__dirname, '.sitemap.xml')
|
|
|
|
sitemapTmpl = nunjucks.compile(fs.readFileSync(sitemapSrc, 'utf8'), env)
|
|
|
|
|
|
|
|
return sitemapTmpl
|
|
|
|
}
|