Better URLs!
This commit is contained in:
parent
bdf6a22857
commit
93ee8574b3
1 changed files with 25 additions and 2 deletions
27
index.js
27
index.js
|
@ -40,8 +40,9 @@ function pageUpdate() {
|
||||||
for (var i = 0; i < postsArray.length; i++) {
|
for (var i = 0; i < postsArray.length; i++) {
|
||||||
var addedHTML = ""
|
var addedHTML = ""
|
||||||
var post = postsArray[i]
|
var post = postsArray[i]
|
||||||
|
post = post.substring(post.indexOf("]") + 2, post.length - 3)
|
||||||
|
|
||||||
addedHTML += `<h2><a href="./post/${post}">${post.substring(post.indexOf("]") + 2, post.length - 3)}</h2></a>`
|
addedHTML += `<h2><a href="./post/${post.split(' ').join('_')}">${post}</h2></a>`
|
||||||
|
|
||||||
html += addedHTML
|
html += addedHTML
|
||||||
}
|
}
|
||||||
|
@ -57,9 +58,31 @@ watcher
|
||||||
.on('unlink', pageUpdate)
|
.on('unlink', pageUpdate)
|
||||||
|
|
||||||
app.get('/post/:post*', (req, res) => {
|
app.get('/post/:post*', (req, res) => {
|
||||||
var post = fs.readFileSync(path.join(postsPath, req.params.post)).toString()
|
|
||||||
var postName = req.params.post
|
var postName = req.params.post
|
||||||
|
|
||||||
|
var postsArray = fs.readdirSync(postsPath).reverse()
|
||||||
|
var postsDict = {}
|
||||||
|
|
||||||
|
for (let index = 0; index < postsArray.length; index++) {
|
||||||
|
const post = postsArray[index];
|
||||||
|
postsDict[post.substring(post.indexOf("]") + 2, post.length - 3).split(' ').join('_')] = post
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(postsDict, postName)
|
||||||
|
|
||||||
|
if (!postsDict[postName]) {
|
||||||
|
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
||||||
|
html = html.replace("{POST_TITLE}", "Not found!")
|
||||||
|
html = html.replace("{POST}", "<p>Couldn't find this post... Maybe try clearing your cache? Violet's Limbo is currently going through alot of backend changes, so expect things to break!</p>")
|
||||||
|
res.send(html)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
postName = postsDict[postName]
|
||||||
|
|
||||||
|
var post = fs.readFileSync(path.join(postsPath, postName)).toString()
|
||||||
|
|
||||||
post = mkthtml.makeHtml(post)
|
post = mkthtml.makeHtml(post)
|
||||||
|
|
||||||
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
||||||
|
|
Loading…
Reference in a new issue