summaryrefslogtreecommitdiff
path: root/src/routes/static.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/static.ts')
-rw-r--r--src/routes/static.ts46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/routes/static.ts b/src/routes/static.ts
index f57d1db..33f0225 100644
--- a/src/routes/static.ts
+++ b/src/routes/static.ts
@@ -6,29 +6,31 @@ import { markdownToSanitizedHTML } from "../util/markdown.js";
const config = getConfig();
const router = Router();
-config.static_pages
- .filter((page) => page.path?.startsWith("/") && page.filename)
- .forEach((page) => {
- router.get(page.path, (_: Request, res: Response) => {
- try {
- if (fs.existsSync(`./static/${page.filename}`)) {
- const fileBody = fs.readFileSync(
- `./static/${page.filename}`,
- "utf-8",
- );
- const parsed = markdownToSanitizedHTML(fileBody);
- return res.render("static", {
- title: page.title,
- content: parsed,
- ...frontendConfig(),
- });
+if (config.static_pages?.length) {
+ config.static_pages
+ .filter((page) => page.path?.startsWith("/") && page.filename)
+ .forEach((page) => {
+ router.get(page.path, (_: Request, res: Response) => {
+ try {
+ if (fs.existsSync(`./static/${page.filename}`)) {
+ const fileBody = fs.readFileSync(
+ `./static/${page.filename}`,
+ "utf-8",
+ );
+ const parsed = markdownToSanitizedHTML(fileBody);
+ return res.render("static", {
+ title: page.title,
+ content: parsed,
+ ...frontendConfig(),
+ });
+ }
+ return res.status(404).render("404", frontendConfig());
+ } catch (err) {
+ console.error(err);
+ return res.status(404).render("404", frontendConfig());
}
- return res.status(404).render("404", frontendConfig());
- } catch (err) {
- console.error(err);
- return res.status(404).render("404", frontendConfig());
- }
+ });
});
- });
+}
export default router;