Web/node/sitemap.js
2019-10-04 23:33:45 +02:00

48 lines
1.3 KiB
JavaScript

const {
createSitemap
} = require('sitemap');
const fs = require("fs");
module.exports = function (app) {
app.get('/sitemap.xml', function (_req, res) {
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
}
]
});
fs.readFile(__dirname + "/../blog/posts.json", function (_, data) {
let json = JSON.parse(data);
for (let post of json) {
sitemap.add({
url: "/#blog-" + post["id"],
priority: 0.4
});
}
res.header('Content-Type', 'application/xml');
res.send(sitemap.toXML());
});
});
}