From c44b72ffb94f8168ff23dd6df72156ff6ca594a7 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 3 Oct 2019 18:17:50 +0200 Subject: [PATCH] added a sitemap generator, let's see if this works --- node/sitemap.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ robots.txt | 1 + 2 files changed, 50 insertions(+) create mode 100644 node/sitemap.js create mode 100644 robots.txt diff --git a/node/sitemap.js b/node/sitemap.js new file mode 100644 index 0000000..993b23e --- /dev/null +++ b/node/sitemap.js @@ -0,0 +1,49 @@ +const express = require('express'); +const { + createSitemap +} = require('sitemap'); +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); +}); +app.listen(3000); \ No newline at end of file diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..cac6e4d --- /dev/null +++ b/robots.txt @@ -0,0 +1 @@ +Sitemap: https://ellpeck.de/sitemap.xml \ No newline at end of file