summaryrefslogtreecommitdiff
path: root/src/sitemap.js
blob: 1c07f99e79214fbb1ca23102d2e485408a26d8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)}