.
This commit is contained in:
		@@ -1,22 +1,12 @@
 | 
			
		||||
import router from "../router.mjs";
 | 
			
		||||
import cfg from "../../../config.json";
 | 
			
		||||
import fs from "fs";
 | 
			
		||||
import path from "path";
 | 
			
		||||
import url from "url";
 | 
			
		||||
import sql from "../sql.mjs";
 | 
			
		||||
import lib from "../lib.mjs";
 | 
			
		||||
import tpl from "../tpl.mjs";
 | 
			
		||||
 | 
			
		||||
const templates = {
 | 
			
		||||
  contact:  fs.readFileSync("./views/contact.html",         "utf-8"),
 | 
			
		||||
  how:      fs.readFileSync("./views/how.html",             "utf-8"),
 | 
			
		||||
  index:    fs.readFileSync("./views/index.html",           "utf-8"),
 | 
			
		||||
  item:     fs.readFileSync("./views/item.html",            "utf-8"),
 | 
			
		||||
  snippets: {
 | 
			
		||||
    navbar: fs.readFileSync("./views/snippets/navbar.html", "utf-8")
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
tpl.snippets = templates.snippets;
 | 
			
		||||
tpl.readdir("views");
 | 
			
		||||
 | 
			
		||||
router.get("/", async (req, res) => {
 | 
			
		||||
  const query = await sql.query("select id, mime from items order by id desc limit 300");
 | 
			
		||||
@@ -25,7 +15,7 @@ router.get("/", async (req, res) => {
 | 
			
		||||
    last: query[query.length - 1].id
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  res.reply({ body: tpl.render(templates.index, data) });
 | 
			
		||||
  res.reply({ body: tpl.render("views/index", data) });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.get(/^\/([0-9]+)$/, async (req, res) => {
 | 
			
		||||
@@ -58,11 +48,11 @@ router.get(/^\/([0-9]+)$/, async (req, res) => {
 | 
			
		||||
    next: query[1].length ? query[1][0].id : null,
 | 
			
		||||
    prev: query[2].length ? query[2][0].id : null
 | 
			
		||||
  };
 | 
			
		||||
  res.reply({ body: tpl.render(templates.item, data) });
 | 
			
		||||
  res.reply({ body: tpl.render("views/item", data) });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.get(/^\/(contact|help|how)$/, (req, res) => {
 | 
			
		||||
  res.reply({ body: tpl.render(templates[req.url.split[0]]) });
 | 
			
		||||
  res.reply({ body: tpl.render(`views/${req.url.split[0]}`) });
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
router.get("/random", async (req, res) => {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,18 +1,24 @@
 | 
			
		||||
import fs from "fs";
 | 
			
		||||
import path from "path";
 | 
			
		||||
 | 
			
		||||
export default new class {
 | 
			
		||||
  snippets = {};
 | 
			
		||||
  #templates = {};
 | 
			
		||||
  #syntax = [
 | 
			
		||||
    [ "each", t => {
 | 
			
		||||
      const tmp = t.slice(4).trim().split(" ");
 | 
			
		||||
      return `util.forEach(${tmp[0]},(${(tmp[1] === "as" && tmp[2]) ? tmp[2] : "value"},key)=>{`;
 | 
			
		||||
    } ],
 | 
			
		||||
    [ "each", (t, args = t.slice(4).trim().split(" ")) => `util.forEach(${args[0]},(${(args[1] === "as" && args[2]) ? args[2] : "value"},key)=>{` ],
 | 
			
		||||
    [ "/each", () => "});" ],
 | 
			
		||||
    [ "if", t => `if(${t.slice(2).trim()}){` ],
 | 
			
		||||
    [ "elseif", t => `}else if(${t.slice(6).trim()}){` ],
 | 
			
		||||
    [ "else", () => "}else{" ],
 | 
			
		||||
    [ "/if", () => "}" ],
 | 
			
		||||
    [ "include", t => `html+=util.snippets["${t.slice(7).trim()}"];`],
 | 
			
		||||
    [ "include", t => `html+=util.tpl["${t.slice(7).trim()}"];`],
 | 
			
		||||
    [ "=", t => `html+=${t.slice(1).trim()};` ]
 | 
			
		||||
  ];
 | 
			
		||||
  readdir(dir, root = dir, rel = dir.replace(`${root}/`, "")) {
 | 
			
		||||
    for(const d of fs.readdirSync(`${path.resolve()}/${dir}`))
 | 
			
		||||
      d.endsWith(".html")
 | 
			
		||||
        ? this.#templates[`${rel}/${d.split(".")[0]}`] = fs.readFileSync(`${dir}/${d}`, "utf-8").replace(/\'/g, "\\'")
 | 
			
		||||
        : this.readdir(`${dir}/${d}`, root);
 | 
			
		||||
  }
 | 
			
		||||
  forEach(o, f) {
 | 
			
		||||
    if(Array.isArray(o))
 | 
			
		||||
      o.forEach(f);
 | 
			
		||||
@@ -22,13 +28,13 @@ export default new class {
 | 
			
		||||
      throw new Error(`${o} is not a iterable object`);
 | 
			
		||||
  }
 | 
			
		||||
  render(tpl, data = {}, f) {
 | 
			
		||||
    return new Function("util", "data", "let html = \"\";with(data){" + tpl
 | 
			
		||||
    return new Function("util", "data", "let html = \"\";with(data){" + this.#templates[tpl]
 | 
			
		||||
      .trim()
 | 
			
		||||
      .replace(/[\n\r]/g, "")
 | 
			
		||||
      .split(/{{\s*([^}]+)\s*}}/)
 | 
			
		||||
      .filter(Boolean)
 | 
			
		||||
      .map(t => !(f = this.#syntax.filter(s => t.startsWith(s[0]))[0]) ? `html+='${t}';` : f[1](t))
 | 
			
		||||
      .join("") + "}return html.trim().replace(/>[\\n\\r\\s]*?</g, '><')")
 | 
			
		||||
      .bind(null, { forEach: this.forEach, snippets: this.snippets })(data);
 | 
			
		||||
      .join("") + "}return html.trim().replace(/>[\\n\\r\\s]*?</g, '><')"
 | 
			
		||||
    ).bind(null, { forEach: this.forEach, tpl: this.#templates })(data);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
  <link rel="stylesheet" type="text/css" href="./s/css/f0ck-custom.css">
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
  {{include navbar}}
 | 
			
		||||
  {{include snippets/navbar}}
 | 
			
		||||
  <div class="container">
 | 
			
		||||
    <div class="contact">
 | 
			
		||||
      <p>Got a problem? We have the answer: <a href="mailto:admin@f0ck.space">admin@f0ck.space</a></p>
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,7 @@
 | 
			
		||||
  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
  {{include navbar}}
 | 
			
		||||
  {{include snippets/navbar}}
 | 
			
		||||
  <div class="container">
 | 
			
		||||
    <div class="irc">
 | 
			
		||||
      <h4>irc.n0xy.net +6697 (ssl only) #f0ck</h4>
 | 
			
		||||
@@ -29,12 +29,12 @@
 | 
			
		||||
      </ul>
 | 
			
		||||
      <h4>What the f0ck is a f0ck?</h4>
 | 
			
		||||
      <p>A f0ck is basically giving a fuck about some internet bullshit, like stupid images, videos and so on, but also
 | 
			
		||||
        for great things like good music taste and shit, it\'s basically "a f0ck was given" and f0ck and it\'s users gave
 | 
			
		||||
        a lot of f0cks over the past years, it\'s not hard to finally start giving a damn f0ck about something, just
 | 
			
		||||
        for great things like good music taste and shit, it's basically "a f0ck was given" and f0ck and it's users gave
 | 
			
		||||
        a lot of f0cks over the past years, it's not hard to finally start giving a damn f0ck about something, just
 | 
			
		||||
        f0ck.it dood!</p>
 | 
			
		||||
      <h4>how the f0ck to f0ck, you ask?</h4>
 | 
			
		||||
      <p>f0ck will f0ck any media link posted in the channel ending with: jpg|gif|png|webm|mp3|mp4|ogg|flac</p>
 | 
			
		||||
      <p>If you don\'t want f0ck to f0ck it put !ignore behind your link. Example:
 | 
			
		||||
      <p>If you don't want f0ck to f0ck it put !ignore behind your link. Example:
 | 
			
		||||
        https://retard-journal.com/stupidshit.png !ignore</a>
 | 
			
		||||
        <p>f0ck will only f0ck media links with the maximum size of 30MB for cool people 80MB</p>
 | 
			
		||||
        <p>YouTube Links are currently not working, if you really want to f0ck them, you gotta download it yourself and
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@
 | 
			
		||||
  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
  {{include navbar}}
 | 
			
		||||
  {{include snippets/navbar}}
 | 
			
		||||
  <div class="container-fluid">
 | 
			
		||||
    <ul id="posts" data-last="{{=last}}">
 | 
			
		||||
      {{each items as item}}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@
 | 
			
		||||
  <meta charset="utf-8" />
 | 
			
		||||
</head>
 | 
			
		||||
<body>
 | 
			
		||||
  {{include navbar}}
 | 
			
		||||
  {{include snippets/navbar}}
 | 
			
		||||
  <div class="container">
 | 
			
		||||
    <div class="controls">
 | 
			
		||||
      <a id="rndbtn" href="/random">Random</a>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user