Changed how comments are stored and how data is retrieved
This commit is contained in:
@@ -31,11 +31,10 @@ router.post("/submit_comment", (req,res) => {
|
||||
new_comment = {
|
||||
"name": name,
|
||||
"content": content,
|
||||
"id": comments[postID].length,
|
||||
"id": comments[postID]['comments'].length,
|
||||
"pubdate": unix_timestamp,
|
||||
"postID": postID,
|
||||
};
|
||||
comments[postID].push(new_comment);
|
||||
comments[postID]['comments'].push(new_comment);
|
||||
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
||||
}
|
||||
|
||||
@@ -59,8 +58,9 @@ router.post("/submit_post", (req,res) => {
|
||||
|
||||
else if (users[func.get_userID(username)]['hash'] == password) { // Password matches
|
||||
console.log(username, "is submitting a post titled:", title);
|
||||
id = posts.length
|
||||
posts.push({
|
||||
"id": posts.length,
|
||||
"id": id,
|
||||
"userID": func.get_userID(username),
|
||||
"title": title,
|
||||
"content": content,
|
||||
@@ -69,7 +69,7 @@ router.post("/submit_post", (req,res) => {
|
||||
"tags": tags,
|
||||
})
|
||||
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
||||
comments.push([])
|
||||
comments.push({'id': id, 'comments': []})
|
||||
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`)
|
||||
res.redirect(302, "/");
|
||||
}
|
||||
@@ -216,7 +216,7 @@ router.get('/search', (req, res) => {
|
||||
console.log('searching for: ', search_term);
|
||||
const search_results = data.searchdata(search_term, search_type); // data.searchdata returns an array of search results
|
||||
|
||||
res.render('partials/search', {
|
||||
res.render('pages/search', {
|
||||
config,
|
||||
locale,
|
||||
search_results,
|
||||
|
||||
Reference in New Issue
Block a user