0.0.3 • Published 8 months ago
potatoprotocol v0.0.3
pbp njs
Example:
index.js
const Potato = require('./potato');
const ejs = require('ejs');
const domain = "base.net"; // domain, change it to whatever u want
const potato = new Potato(domain);
// using files + <## variables ##>
potato.use("", (skin) => {
console.log("main page visited by " + skin.id);
skin.render("index.html", { name: "vnti" });
});
// using plain display + ejs
potato.use('help/:text', (skin) => {
const text = skin.params.text;
console.log("someone visited the help page with param:", text);
const template = `
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: rgb(16,0,0);
color: white !important;
}
</style>
</head>
<body>
<h1>help for <%= text %>:\n</h1>
</body>
`;
const renderedContent = ejs.render(template, { text });
skin.display(renderedContent);
});
// custom 404 page
potato.setNotFoundCallback((data) => {
const template = `
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<h1><a href="pbp://${domain}/help/idk">come back home</a></h1>
</body>
`;
const renderedContent = ejs.render(template, {});
potato.do('show', { ...data, content: renderedContent });
});
potato.run()
/views/index.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
background-color: #000000;
color: white !important;
}
</style>
</head>
<body>
<h1>you have visited main page! my name is <a href="pbp://base.net/help/idk"><## name ##></a></h1>
</body>
</html>