Blog in development
This commit is contained in:
parent
2b724bc2db
commit
7e52727bf0
12 changed files with 389 additions and 10 deletions
33
blog.js
Normal file
33
blog.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
const api = require("./api.js"),
|
||||
app = require("./expressHandler.js").app,
|
||||
showdown = require("showdown"),
|
||||
pageUpdater = require("./pageUpdater.js"),
|
||||
fs = require("fs"),
|
||||
path = require("path")
|
||||
mkhtml = new showdown.Converter()
|
||||
|
||||
mkhtml.setFlavor("github")
|
||||
|
||||
app.use((req, res, next) => {
|
||||
if (req.path.includes("blog") && api.blogPosts) {
|
||||
var postName = decodeURIComponent(req.path.substring(6, req.path.length - 1))
|
||||
for (var i = 0; i < api.blogPosts.length; i++) {
|
||||
var post = api.blogPosts[i]
|
||||
|
||||
if (post.folder == postName || post.folder == decodeURIComponent(post.title)) {
|
||||
var mkdwn = post.data
|
||||
var html = mkhtml.makeHtml(mkdwn)
|
||||
|
||||
html = fs.readFileSync(path.join(__dirname, "assets/html/blog.html")).toString().replace("{BLOG_POST}", html)
|
||||
|
||||
html = pageUpdater.converter(html, false)
|
||||
|
||||
res.send(html)
|
||||
return
|
||||
}
|
||||
}
|
||||
next()
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue