hexo/node_modules/hexo-generator-baidu-sitemap/lib/generator.js

28 lines
636 B
JavaScript
Raw Normal View History

2023-09-25 15:58:56 +08:00
var ejs = require('ejs');
var pathFn = require('path');
var fs = require('fs');
var sitemapSrc = pathFn.join(__dirname, '../baidusitemap.ejs');
var sitemapTmpl = ejs.compile(fs.readFileSync(sitemapSrc, 'utf8'));
module.exports = function(locals){
var config = this.config;
var posts = [].concat(locals.posts.toArray(), locals.pages.toArray())
.filter(function(post){
return post.baidusitemap !== false;
})
.sort(function(a, b){
return b.updated - a.updated;
});
var xml = sitemapTmpl({
config: config,
posts: posts
});
return {
path: config.baidusitemap.path,
data: xml
};
};