diff --git a/ressources/site.yml b/ressources/site.yml new file mode 100644 index 0000000..ee14506 --- /dev/null +++ b/ressources/site.yml @@ -0,0 +1,4 @@ +title: "Test" +language: "de" +domain: "test.lan" +https: true diff --git a/src/factories/sitemap.js b/src/factories/sitemap.js index 1fd12f7..6a82934 100644 --- a/src/factories/sitemap.js +++ b/src/factories/sitemap.js @@ -32,7 +32,7 @@ class Sitemap { addPage(page) { if (this._isValid(page)) { this._urls.push({ - loc: 'https://' + this._site.domain + page.pathname + '/' + page.filename, + loc: 'https://' + this._site.domain + page.path, lastmod: dayjs().format() }) } @@ -69,7 +69,7 @@ class Sitemap { }) } - if (page.type !== 'html') { + if (page.extensions !== 'html') { result = false } @@ -108,4 +108,4 @@ class Sitemap { } } -module.exports = Sitemap \ No newline at end of file +module.exports = Sitemap diff --git a/test/sitemap.js b/test/sitemap.js new file mode 100644 index 0000000..41874e7 --- /dev/null +++ b/test/sitemap.js @@ -0,0 +1,30 @@ +const { assert } = require('chai') +const fs = require('fs') + +const PagesQuery = require('./../src/queries/pages.js') +const configStore = require('./../src/config.js') +const parseYamlFile = require('./../src/parsers/yaml.js') +const Sitemap = require('./../src/factories/sitemap.js') + +describe('Sitemap', function () { + + configStore.set('source', './ressources') + configStore.set('destination', './dist') + + const file = fs.readFileSync('./ressources/site.yml', 'utf8') + const siteConfig = parseYamlFile(file) + + const query = new PagesQuery('./ressources') + const results = query.find() + + const sitemap = new Sitemap(siteConfig) + + results.forEach((page) => { + sitemap.addPage(page) + }) + + // check results + it('loc-tag with url', function() { + assert.match(sitemap.getXmlAsString(), /https:\/\/test.lan\/blog\/article.html<\/loc>/) + }) +})