New System
This commit is contained in:
parent
93ee8574b3
commit
3c6270f83d
2 changed files with 37 additions and 32 deletions
50
index.js
50
index.js
|
@ -13,7 +13,7 @@ var dataPath = path.join(__dirname, 'data')
|
||||||
var postsPath = path.join(dataPath, 'posts')
|
var postsPath = path.join(dataPath, 'posts')
|
||||||
var staticPath = path.join(__dirname, 'static')
|
var staticPath = path.join(__dirname, 'static')
|
||||||
|
|
||||||
var watcher = chokidar.watch(postsPath)
|
var watcher = chokidar.watch(dataPath)
|
||||||
|
|
||||||
var app = express()
|
var app = express()
|
||||||
|
|
||||||
|
@ -33,16 +33,23 @@ app.listen(PORT, () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
function pageUpdate() {
|
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 = ""
|
var html = ""
|
||||||
|
|
||||||
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.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
|
html += addedHTML
|
||||||
}
|
}
|
||||||
|
@ -53,42 +60,35 @@ function pageUpdate() {
|
||||||
}
|
}
|
||||||
|
|
||||||
watcher
|
watcher
|
||||||
.on('add', pageUpdate)
|
|
||||||
.on('change', pageUpdate)
|
.on('change', pageUpdate)
|
||||||
.on('unlink', pageUpdate)
|
|
||||||
|
|
||||||
app.get('/post/:post*', (req, res) => {
|
app.get('/post/:post*', (req, res) => {
|
||||||
var postName = req.params.post
|
var postName = req.params.post
|
||||||
|
|
||||||
var postsArray = fs.readdirSync(postsPath).reverse()
|
var data = JSON.parse(fs.readFileSync(path.join(dataPath, 'data.json')))
|
||||||
var postsDict = {}
|
var postsArray = data.posts
|
||||||
|
|
||||||
for (let index = 0; index < postsArray.length; index++) {
|
for (let index = 0; index < postsArray.length; index++) {
|
||||||
const post = postsArray[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()
|
var html = fs.readFileSync(path.join(__dirname, 'resources/postPage.html')).toString()
|
||||||
html = html.replace("{POST_TITLE}", "Not found!")
|
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>")
|
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)
|
res.send(html)
|
||||||
|
|
||||||
return
|
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))
|
|
||||||
|
|
||||||
res.send(html)
|
|
||||||
})
|
})
|
|
@ -10,7 +10,12 @@
|
||||||
<body>
|
<body>
|
||||||
<h2><a href="https://violets-purgatory.dev">Home</a></h2>
|
<h2><a href="https://violets-purgatory.dev">Home</a></h2>
|
||||||
<h1>Violet's Limbo</h1>
|
<h1>Violet's Limbo</h1>
|
||||||
|
<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>
|
<h2>Posts:</h2>
|
||||||
{POSTS}
|
{POSTS}
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in a new issue