You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
keys/prepare.js

35 lines
1.3 KiB
JavaScript

let fs = require("fs");
let path = require("path");
let mkdirp = require("mkdirp");
const staticDir = path.join(__dirname, "static");
module.exports = (app) => {
function renderAndSave(file, template, options) {
file = path.join(staticDir, file);
mkdirp.sync(path.join(file, ".."));
options.layout = "html";
app.render(template, options, (e, r) => {
if (e) return fs.writeFile(file, "<!DOCTYPE html><html><head><title>Something went wrong!</title></head><body><h1>Something went wrong!</h1><p>Could not render this page! Please contact the administrator!</p></body></html>", () => undefined);
return fs.writeFile(file, r, () => undefined);
});
}
if (!fs.existsSync(staticDir)) fs.mkdirSync(staticDir);
[
["index.htm", "linkList", {
title: "Key Server of banananet.work",
links: [
{href: "/ssh/", name: "Public SSH Keys"},
],
}],
["ssh/index.htm", "linkList", {
title: "SSH Keys of banananet.work",
links: [
{href: "/ssh/user", name: "Get all user keys"},
{href: "/ssh/ca/", name: "Certificate Authorities"},
]
}],
].forEach(e => renderAndSave(e[0], e[1], e[2]));
};