Commit 83d1ff2c authored by Elias Ojala's avatar Elias Ojala

Markdown based CMS for glossary

parent 13ee7eb7
import { NextFunction, Request, Response, Router } from "express";
import showdown from "showdown";
import path from "path";
import { promises as fsPromises } from "fs";
const router: Router = Router();
router.get("/:page?", async (req: Request, res: Response, next: NextFunction) => {
const pageName = req.params.page ? req.params.page : "index";
const filePath = path.resolve(
__dirname, "..", "..",
"views", "glossary", "pages", `${pageName}.md`
);
fsPromises.readFile(filePath)
.then(markdown => {
const mdConverter = new showdown.Converter();
const html = mdConverter.makeHtml(markdown.toString());
const title = "Title";
res.render("glossary/template.twig", {
// "canonical_url": "/glossary/",
"title": `${title} - Glossary - ${process.env.APP_NAME}`,
"disable_title_prefix": true,
"content": html,
})
})
.catch(err => {
/**
* If file can't be found, lead to 404.
* Otherwise, 500.
*
* "ENOENT: 2 - No such file or directory"
*/
if(err.code === "ENOENT") {
next();
} else {
next(err);
}
});
});
export const GlossaryController: Router = router;
......@@ -10,3 +10,4 @@ export * from "./net.controller";
export * from "./explore.controller";
export * from "./tld.controller";
export * from "./tor.controller";
export * from "./glossary.controller";
# Glossary
Welcome to TelcoDB's glossary page.
{% extends 'layouts/default.twig' %}
{% block body %}{{ content }}{% endblock %}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment