-
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathgenerator.js
51 lines (44 loc) · 1.19 KB
/
generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
const micromatch = require('micromatch');
const template = require('./template');
module.exports = function(locals) {
const { config } = this;
const { sitemap, skip_render } = config;
const { tags: tagsCfg, categories: catsCfg } = sitemap;
const skipRenderList = [
'**/*.js',
'**/*.css'
];
if (Array.isArray(skip_render)) {
skipRenderList.push(...skip_render);
} else if (typeof skip_render === 'string') {
if (skip_render.length > 0) {
skipRenderList.push(skip_render);
}
}
const posts = [].concat(locals.posts.toArray(), locals.pages.toArray())
.filter(post => {
return post.sitemap !== false && !isMatch(post.source, skipRenderList);
})
.sort((a, b) => {
return b.updated - a.updated;
});
if (posts.length <= 0) {
sitemap.rel = false;
return;
}
const res = template(config);
for (const i in res) {
res[i].data = res[i].data.render({
config,
posts,
sNow: new Date(),
tags: tagsCfg ? locals.tags.toArray() : [],
categories: catsCfg ? locals.categories.toArray() : []
});
}
return res;
};
function isMatch(path, patterns) {
return micromatch.isMatch(path, patterns);
}