summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app.js9
-rw-r--r--source/readfile.js19
2 files changed, 28 insertions, 0 deletions
diff --git a/app.js b/app.js
index 7e94983..84c283c 100644
--- a/app.js
+++ b/app.js
@@ -14,6 +14,7 @@ const mime = {
html: 'text/html',
txt: 'text/plain',
css: 'text/css',
+ xml: 'text/xml',
gif: 'image/gif',
jpg: 'image/jpeg',
png: 'image/png',
@@ -78,7 +79,15 @@ class App {
this.data = this.readfile.GetRobots()
this.data.mime.then(output => this.#FileOpen({data: this.data, mime: output, res: res}))
break
+ case 'sitemap.xml':
+ this.data = this.readfile.Sitemap({keys: Array.from(output.keys()), url: process.env.baseUrl})
+ this.data.then(data => {
+ res.set('Content-Type', mime.xml)
+ res.send(data)
+ })
+ break
case 'rss':
+ res.set('Content-Type', mime.xml)
rss.GetFeed({
title: process.env.rssTitle,
description: process.env.rssDescription,
diff --git a/source/readfile.js b/source/readfile.js
index 9310b8c..def56a1 100644
--- a/source/readfile.js
+++ b/source/readfile.js
@@ -1,5 +1,7 @@
const fs = require('fs')
const path = require('path')
+const { SitemapStream, streamToPromise } = require('sitemap')
+const { Readable } = require('stream')
const logger = require('./logger')()
/*
@@ -71,6 +73,23 @@ class ReadFile {
}
}
}
+ async Sitemap(x) {
+ const object = {
+ keys: x.keys,
+ links: [],
+ remove: ['/', '/blog'],
+ stream: new SitemapStream({hostname: x.url})
+ }
+
+ Array.from(object.remove).forEach(url => {
+ object.keys.splice(object.keys.indexOf(url), 1)
+ object.links.push({url: url, changefreq: 'daily', priority: 1})
+ })
+
+ object.keys.forEach(link => object.links.push({url: link, changefreq: 'weekly', priority: 0.8}))
+
+ return streamToPromise(Readable.from(object.links).pipe(object.stream)).then(data => {return data.toString()})
+ }
GetFile(x) {
const path = x.split('/')
const object = {