diff --git a/helpers/view_loader.js b/helpers/view_loader.js index 0cd2f2d..d1ef5c2 100644 --- a/helpers/view_loader.js +++ b/helpers/view_loader.js @@ -1,4 +1,4 @@ -const Eta = require('eta'); +const pug = require('pug'); const fs = require('fs/promises'); const glob = require('glob'); @@ -7,28 +7,24 @@ const layoutdir = cwd + '/view'; let compiled = {}; - async function loadFile(file) { if (compiled[file]) return compiled[file]; - compiled[file] = Eta.compile(await fs.readFile(file, 'utf8')); - + compiled[file] = await pug.compileFile(file); return compiled[file]; } +async function load(name, data) { + return (await loadFile(layoutdir + '/' + name))(data); +} async function preload() { - glob(layoutdir + '/*.eta', (err, files) => { - files.filter(file => {return !file.startsWith('.');}) - .forEach(file => { - loadFile(file); - }); + await glob(layoutdir + '/**/*', (err, files) => { + files.filter(file => { + return !file.startsWith('.'); + }).forEach(file => { + loadFile(file); + }); }); } - -async function load(name, data) { - return (await loadFile(cwd + '/view/' + name))(data, Eta.config); -} - - module.exports = { load, loadFile, preload } \ No newline at end of file diff --git a/package.json b/package.json index 96b3fcc..266fe56 100644 --- a/package.json +++ b/package.json @@ -13,9 +13,9 @@ "license": "ISC", "dependencies": { "dotenv": "^16.0.3", - "eta": "^2.0.0", "express": "^4.18.2", - "glob": "^8.1.0" + "glob": "^8.1.0", + "pug": "^3.0.2" }, "devDependencies": { "gulp": "^4.0.2" diff --git a/routes/homepage.js b/routes/homepage.js index e047893..52bd6d0 100644 --- a/routes/homepage.js +++ b/routes/homepage.js @@ -1,7 +1,7 @@ const Helpers = require('../helpers'); async function handler(req, res) { - res.send(await Helpers.ViewLoader.load('welcome.eta')); + res.send(await Helpers.ViewLoader.load('hi.pug')); } module.exports = (router) => { diff --git a/view/hi.pug b/view/hi.pug new file mode 100644 index 0000000..2dd9f5a --- /dev/null +++ b/view/hi.pug @@ -0,0 +1 @@ +p hi \ No newline at end of file diff --git a/view/layout/main.eta b/view/layout/main.eta deleted file mode 100644 index e69de29..0000000 diff --git a/view/welcome.eta b/view/welcome.eta deleted file mode 100644 index 739a35a..0000000 --- a/view/welcome.eta +++ /dev/null @@ -1,2 +0,0 @@ -hi
-<%~ Date.now() %> \ No newline at end of file