2019-10-04 22:15:03 +02:00
|
|
|
const {
|
|
|
|
createSitemap
|
|
|
|
} = require('sitemap');
|
|
|
|
const fs = require("fs");
|
|
|
|
|
2019-10-05 01:07:38 +02:00
|
|
|
module.exports = function () {
|
|
|
|
let folder = __dirname + "/../";
|
2019-10-10 12:04:08 +02:00
|
|
|
refreshSitemap(folder);
|
|
|
|
|
2019-10-05 01:07:38 +02:00
|
|
|
fs.watchFile(folder + "blog/posts.json", function (curr, prev) {
|
|
|
|
if (curr.mtime == prev.mtime)
|
|
|
|
return;
|
2019-10-10 12:04:08 +02:00
|
|
|
refreshSitemap(folder);
|
|
|
|
});
|
|
|
|
}
|
2019-10-04 22:15:03 +02:00
|
|
|
|
2019-10-10 12:04:08 +02:00
|
|
|
function refreshSitemap(folder) {
|
|
|
|
console.log("Refreshing sitemap...");
|
2019-10-04 23:20:47 +02:00
|
|
|
|
2019-10-10 12:04:08 +02:00
|
|
|
let sitemap = createSitemap({
|
|
|
|
hostname: 'https://ellpeck.de',
|
|
|
|
urls: [{
|
|
|
|
url: '/',
|
|
|
|
priority: 0.8
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: '/#projects',
|
|
|
|
changefreq: 'monthly'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: '/#social',
|
|
|
|
changefreq: 'yearly'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: '/#about',
|
|
|
|
changefreq: 'monthly'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
url: '/#blog',
|
|
|
|
changefreq: 'weekly',
|
|
|
|
priority: 0.6
|
2019-11-20 20:55:01 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
url: '/foefrenzy',
|
|
|
|
priority: 0.7
|
2019-11-24 03:20:57 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
url: '/foefrenzy/maps'
|
2019-10-04 23:20:47 +02:00
|
|
|
}
|
2019-10-10 12:04:08 +02:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
fs.readFile(folder + "blog/posts.json", function (_, data) {
|
|
|
|
let json = JSON.parse(data);
|
|
|
|
|
|
|
|
for (let post of json) {
|
|
|
|
sitemap.add({
|
2019-11-20 22:17:58 +01:00
|
|
|
url: "/blog-" + post.id
|
2019-10-10 12:04:08 +02:00
|
|
|
});
|
|
|
|
}
|
2019-10-04 22:15:03 +02:00
|
|
|
|
2019-10-10 12:04:08 +02:00
|
|
|
fs.writeFile(folder + "/sitemap.xml", sitemap.toXML(), function (_, _) {});
|
2019-10-04 22:15:03 +02:00
|
|
|
});
|
2019-10-04 23:20:47 +02:00
|
|
|
}
|