New System
This commit is contained in:
parent
93ee8574b3
commit
3c6270f83d
2 changed files with 37 additions and 32 deletions
60
index.js
60
index.js
|
@ -13,7 +13,7 @@ var dataPath = path.join(__dirname, 'data')
|
|||
var postsPath = path.join(dataPath, 'posts')
|
||||
var staticPath = path.join(__dirname, 'static')
|
||||
|
||||
var watcher = chokidar.watch(postsPath)
|
||||
var watcher = chokidar.watch(dataPath)
|
||||
|
||||
var app = express()
|
||||
|
||||
|
@ -33,16 +33,23 @@ app.listen(PORT, () => {
|
|||
})
|
||||
|
||||
function pageUpdate() {
|
||||
var postsArray = fs.readdirSync(postsPath).reverse()
|
||||
var data = JSON.parse(fs.readFileSync(path.join(dataPath, 'data.json')))
|
||||
var postsArray = data.posts
|
||||
|
||||
var html = ""
|
||||
|
||||
for (var i = 0; i < postsArray.length; i++) {
|
||||
var addedHTML = ""
|
||||
var post = postsArray[i]
|
||||
post = post.substring(post.indexOf("]") + 2, post.length - 3)
|
||||
|
||||
|
||||
addedHTML += `<h2><a href="./post/${post.split(' ').join('_')}">${post}</h2></a>`
|
||||
addedHTML +=
|
||||
`<div class="project">
|
||||
<a style="text-decoration: none;" href="./post/${post.path}">
|
||||
<h2>${post.name}</h2>
|
||||
<p style="color: darkgray; font-size: 1rem;">Path: <code>/post/${post.path}</code></p>
|
||||
</a>
|
||||
</div>`
|
||||
|
||||
html += addedHTML
|
||||
}
|
||||
|
@ -53,42 +60,35 @@ function pageUpdate() {
|
|||
}
|
||||
|
||||
watcher
|
||||
.on('add', pageUpdate)
|
||||
.on('change', pageUpdate)
|
||||
.on('unlink', pageUpdate)
|
||||
|
||||
app.get('/post/:post*', (req, res) => {
|
||||
var postName = req.params.post
|
||||
|
||||
var postsArray = fs.readdirSync(postsPath).reverse()
|
||||
var postsDict = {}
|
||||
var data = JSON.parse(fs.readFileSync(path.join(dataPath, 'data.json')))
|
||||
var postsArray = data.posts
|
||||
|
||||
for (let index = 0; index < postsArray.length; index++) {
|
||||
const post = postsArray[index];
|
||||
postsDict[post.substring(post.indexOf("]") + 2, post.length - 3).split(' ').join('_')] = post
|
||||
|
||||
if (post.path == postName) {
|
||||
postContent = mkthtml.makeHtml(fs.readFileSync(path.join(postsPath, post.path)).toString())
|
||||
|
||||
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
||||
|
||||
html = html.replace('{POST}', postContent)
|
||||
html = html.replace('{POST_TITLE}', post.name)
|
||||
|
||||
res.send(html)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
||||
|
||||
html = html.replace('{POST}', post)
|
||||
html = html.replace('{POST_TITLE}', postName.substring(postName.indexOf("]") + 2, postName.length - 3))
|
||||
|
||||
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
|
||||
|
||||
})
|
|
@ -10,7 +10,12 @@
|
|||
<body>
|
||||
<h2><a href="https://violets-purgatory.dev">Home</a></h2>
|
||||
<h1>Violet's Limbo</h1>
|
||||
<h2>Posts:</h2>
|
||||
{POSTS}
|
||||
<div class="fadediv">
|
||||
<p>Violet's Limbo is just a bunch of random blogs I decided to post, because why not :></p>
|
||||
<p>Currently its very early in development, and is going through a large rewrite :P</p>
|
||||
<p>Enjoy my bad opinions!<hr></p>
|
||||
<h2>Posts:</h2>
|
||||
{POSTS}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in a new issue