From 4c36f505ba9d513341c3425f6780616eb50eb029 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 4 Oct 2019 11:20:12 +0200 Subject: [PATCH] made sitemap generation properly dynamic --- node/sitemap.js | 77 ++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/node/sitemap.js b/node/sitemap.js index 993b23e..9756bdc 100644 --- a/node/sitemap.js +++ b/node/sitemap.js @@ -5,45 +5,44 @@ const { const fs = require("fs"); let app = express(); -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) { - var json = JSON.parse(data); - for (var post of json) { - sitemap.add({ - url: "/#blog-" + post["id"], - priority: 0.4 - }); - } -}); - app.get('/sitemap.xml', function (_req, res) { - let xml = sitemap.toXML(); - res.header('Content-Type', 'application/xml'); - res.send(xml); + 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) { + var json = JSON.parse(data); + for (var post of json) { + sitemap.add({ + url: "/#blog-" + post["id"], + priority: 0.4 + }); + } + + res.header('Content-Type', 'application/xml'); + res.send(sitemap.toXML()); + }); }); app.listen(3000); \ No newline at end of file