-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (45 loc) · 1.32 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const express = require('express');
const app = express();
const fs = require('fs');
const matter = require('gray-matter');
const port = 4400
app.set('view engine', 'ejs')
app.get('/', (req, res) => {
const page = matter.read(__dirname + '/index.md');
let result = page.content;
res.render("pages/index", {
page: result
});
})
app.get('/about', (req, res) => {
const page = matter.read(__dirname + '/about.md');
let result = page.content;
res.render("pages/about", {
page: result
});
})
app.get('/context', (req, res) => {
const posts = fs.readdirSync(__dirname + '/_contexts').filter(file => file.endsWith('.md'));
res.render("pages/contexts", {
posts: posts
});
})
app.get("/catalog", (req, res) => {
const posts = fs.readdirSync(__dirname + '/_schemas').filter(file => file.endsWith('.md'));
res.render("pages/catalog", {
posts: posts
});
});
app.get("/:article", (req, res) => {
// read the markdown file
const file = matter.read(__dirname + '/_schemas/' + req.params.article + '.md');
var result = file.content;
res.render("pages/article", {
post: result,
title: file.data.title,
description: file.data.description,
});
});
app.listen(port, () => {
console.log(`App listening at port ${port}`)
})