diff --git a/build/index.js b/build/index.js new file mode 100644 index 0000000..689480c --- /dev/null +++ b/build/index.js @@ -0,0 +1,33 @@ +const { XMLDoc, XMLNode } = require('./xml.js'); +const fs = require('fs').promises; +const path = require('path'); + +async function walk(dir) { + let files = await fs.readdir(dir); + files = await Promise.all(files.map(async file => { + const filePath = path.join(dir, file); + const stats = await fs.stat(filePath); + if (stats.isDirectory()) return walk(filePath); + else if(stats.isFile()) return filePath; + })); + + return files.reduce((all, folderContents) => all.concat(folderContents), []); +} + +walk('./site').then(async (files) => { + let file = true; + const map = new XMLDoc(); + while (file = files.shift()) { + const node = new XMLNode('x-file'); + node.attrs['path'] = file.replace('site/', ''); + map.appendChild(node); + } + try { + await (fs.stat('./site/index.xml').catch((err) => {}).then((stats) => { + fs.unlink('./site/index.xml').catch((err) => {}).then(() => console.log('Deleted existing map succesfully.')).finally(); + })); + } catch { + } finally { + fs.writeFile('./site/index.xml', map.toString(), 'utf8').catch((err) => console.error('Failed to write index.xml\n', err)).then(() => console.log('Wrote index.xml')); + } +}); diff --git a/build/xml.js b/build/xml.js new file mode 100644 index 0000000..49ccd38 --- /dev/null +++ b/build/xml.js @@ -0,0 +1,30 @@ +const XMLNode = function XMLNode(type) { + this.children = new Array(); + this.attrs = new Object(); + this.type = type; + this.root = false; + Object.defineProperty(this, 'textContent', { + set(value) { + this.children = [String(value)]; + return true; + }, + get() { + return ''; + } + }); + this.toString = function() { + return `${(`<${this.type} ` + Object.entries(this.attrs).map(attr => `${attr[0]}="${attr[1]}"`)).trimEnd()}>${this.children.map(child => child.toString()).join('')}` + }; + this.appendChild = function(...children) { + this.children.push(...children); + }; +} +const XMLDoc = function XMLDoc() { + XMLNode.apply(this, ['xml']); + this.root = true; + this._toString = this.toString; + this.toString = function() { + return `${this._toString()}`; + }; +}; +module.exports = { XMLNode, XMLDoc }; diff --git a/index.html b/index.html deleted file mode 100644 index 16d810a..0000000 --- a/index.html +++ /dev/null @@ -1 +0,0 @@ -meow meow im a cow diff --git a/robots.txt b/site/robots.txt similarity index 100% rename from robots.txt rename to site/robots.txt