commit 9fce47370c062af9f31a82e887a791f9aba9a375
parent ea2dd23c6ccd098e0c53bf3935080cf107c2a9cf
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date: Thu, 20 Jan 2022 20:07:47 -0800
Front page items.
Diffstat:
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/server.ts b/server.ts
@@ -39,7 +39,7 @@ class LSStat {
this.numLinks = stats.nlink;
this.fileSize = stats.size;
this.mtime = lsTime(stats.mtimeMs);
- this.basename = path.parse(path.basename(thePath)).name;
+ this.basename = thePath;
}
}
@@ -125,7 +125,19 @@ app.get('/files', (req, res, next) => {
});
// LS everything.
-const frontPageItems = lsList('public', '.html', 'main', 'software', 'sneed', 'files');
+const frontPageItems = lsList('.', '.html', 'main', 'software', 'sneed');
+
+app.get('/:item', (req, res, next) => {
+ let item = req.params.item.toLowerCase();
+ if(fs.existsSync(item)) {
+ res.status(200).render('post', { text : fs.readFileSync(item) });
+ }
+ else {
+ // Page not found.
+ res.status(404).render('404');
+ }
+});
+
app.get('/', (req, res, next) => {
res.status(200).render('index', {
entries: frontPageItems
diff --git a/views/404.handlebars b/views/404.handlebars
@@ -0,0 +1 @@
+404
diff --git a/views/post.handlebars b/views/post.handlebars
@@ -0,0 +1 @@
+Post