summaryrefslogtreecommitdiff
path: root/src/sitemap.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/sitemap.js')
-rw-r--r--src/sitemap.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/sitemap.js b/src/sitemap.js
new file mode 100644
index 0000000..1c07f99
--- /dev/null
+++ b/src/sitemap.js
@@ -0,0 +1,32 @@
+const buildPages = require('./buildpages')
+const { SitemapStream, streamToPromise } = require('sitemap')
+const { Readable } = require('stream')
+
+class Sitemap {
+ constructor(data) {
+ this.baseURL = data.baseURL
+ this.buildPages = buildPages({baseURL: this.baseURL})
+ this.pages = this.#GetSitemap()
+ }
+
+ Sitemap() {return this.pages}
+
+ #GetSitemap() {
+ const pages = this.buildPages.GetSitemap()
+ const object = {
+ links: [],
+ remove: ['/', '/blog'],
+ stream: new SitemapStream({hostname: this.baseURL})
+ }
+
+ for (let i = 0; i < pages.length; i++) {
+ // ! Default priority
+ object.links.push({url: this.baseURL + pages[i].replace('/', ''), changefreq: 'weekly', priority: 0.8})
+ }
+
+ return streamToPromise(Readable.from(object.links).pipe(object.stream)).then(data => {return data.toString()})
+ //return output
+ }
+}
+
+module.exports = (x) => {return new Sitemap(x)}