diff --git a/src/data.js b/src/data.js
index 937e7e9..bf63618 100644
--- a/src/data.js
+++ b/src/data.js
@@ -14,7 +14,7 @@ export function increment_hitcount(postID = -1) { // -1 Means it will increment
writedata('hitcount', hitcount);
}
else {
- let post = getdata('posts','id', postID);
+ let post = getdata('posts','id', postID)[0];
if (post == 1) // Does not exist
{
return 1
@@ -86,18 +86,19 @@ export function getdata(table_name, key=-1, value=-1) {
{ // id is the index
if (value < result.length && value >= 0)
{
- return result[value]
+ return [result[value]]
}
else
{
- console.log("No object of this ID exists for the selected table")
+ console.log("No object of this ID exists for the selected table", table_name)
return 1
}
}
- return result[func.find_key_value_pair(result, key, value)]
- return -1 // This index doesn't exist
+ let return_value = func.find_key_value_pair(result, key, value)
+ return return_value
}
- return result.slice(- config['data_request_limit'])
+ let return_value = result.slice(- config['data_request_limit'])
+ return return_value
break;
case 'hitcount':
result = func.require_module('../data/data.json') // This file is actually called data.json
diff --git a/src/functions.js b/src/functions.js
index af3b94f..e4c0268 100644
--- a/src/functions.js
+++ b/src/functions.js
@@ -140,6 +140,7 @@ export function render_md(content)
return md.render(content)
};
+/*
export function find_key_value_pair(data_array, key, value) {
for (let i = 0; i < data_array.length; i++) {
if (data_array[i][key] == value) {
@@ -148,3 +149,18 @@ export function find_key_value_pair(data_array, key, value) {
}
return -1
};
+*/
+
+// Returns a list of matches
+export function find_key_value_pair(data_array, key, value) {
+ let return_list = []
+ for (let i = 0; i < data_array.length; i++) {
+ let element = data_array[i][key]
+ if (element == value
+ || (Array.isArray(element) && element.includes(value))) {
+ return_list.push(data_array[i])
+ }
+ }
+ return return_list
+};
+
diff --git a/src/routes/form_actions.js b/src/routes/form_actions.js
index d52b7a8..f68120a 100644
--- a/src/routes/form_actions.js
+++ b/src/routes/form_actions.js
@@ -71,7 +71,7 @@ router.post(`${config.site_path}/submit_post`, (req,res) => {
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
comments.push({'id': id, 'comments': []})
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`)
- res.redirect(302, config.site_path);
+ res.redirect(302, `/post/${id}`);
}
else {
res.render("partials/message", {
diff --git a/src/routes/standard_pages.js b/src/routes/standard_pages.js
index 4d981be..c5c599b 100644
--- a/src/routes/standard_pages.js
+++ b/src/routes/standard_pages.js
@@ -33,16 +33,17 @@ router.get(config.site_path, (req,res) => {
// Users
router.get(`${config.site_path}/user/:username`, (req, res) => {
const userID = func.get_userID(req.params.username)
- let user = data.getdata('users', 'id', userID)
+ let posts = data.getdata('posts', 'userID', userID);
+ let user = data.getdata('users', 'id', userID)[0];
if (userID != -1) {
res.render("pages/user",
{
config,
locale,
- posts: data.getdata('posts'),
+ posts,
user,
userID: userID,
- comments: data.getdata('comments'),
+ comments: data.getdata('comments', 'postID'),
fromUnixTime,
format,
getUnixTime,
@@ -61,7 +62,7 @@ router.get(`${config.site_path}/user/:username`, (req, res) => {
// Posts
router.get(`${config.site_path}/post/:post_index`, (req, res) => {
const postID = parseInt(req.params.post_index)
- let post = data.getdata('posts','id', postID)
+ let post = data.getdata('posts','id', postID)[0]
if (post == 1) { // data.getdata returns error code 1 if nothing is available
res.render("partials/message", {
message: locale.post_doesnt_exist,
@@ -78,8 +79,8 @@ router.get(`${config.site_path}/post/:post_index`, (req, res) => {
locale,
post,
postID,
- user: data.getdata('users','id', post.userID),
- comments: data.getdata('comments','id', postID),
+ user: data.getdata('users','id', post.userID)[0],
+ comments: data.getdata('comments','id', postID)[0]["comments"],
fromUnixTime,
format,
getUnixTime,
diff --git a/src/routes/syndication.js b/src/routes/syndication.js
index 94c2861..5cd0f07 100644
--- a/src/routes/syndication.js
+++ b/src/routes/syndication.js
@@ -18,7 +18,8 @@ router.get(`${config.site_path}/rss`, (req,res) => {
}
else {
res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/global_rss", {
+ res.render("syndication/rss", {
+ users: data.getdata('users'),
config,
posts: data.getdata('posts'),
func,
@@ -26,9 +27,10 @@ router.get(`${config.site_path}/rss`, (req,res) => {
};
});
// user RSS protocol gets
+// TODO specific title field and descriptions??
router.get(`${config.site_path}/user/:username/rss`, (req,res) => {
const username = req.params.username;
- const userID = func.get_userID(username);
+ const user = data.getdata('users','username',username)[0]; // Get the user data
if (config.rss == false) {
res.render("partials/message", {
message: locale.rss_disabled,
@@ -37,11 +39,11 @@ router.get(`${config.site_path}/user/:username/rss`, (req,res) => {
}
else {
res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/user_rss", {
+ res.render("syndication/rss", {
+ users: [user],
config,
- posts: data.getdata('posts'),
+ posts: data.getdata('posts','id',user['id']),
func,
- userID,
})
};
});
@@ -55,7 +57,7 @@ router.get(`${config.site_path}/atom`, (req,res) => {
}
else {
res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/global_atom", {
+ res.render("syndication/atom", {
config,
posts: data.getdata('posts'),
func,
@@ -66,7 +68,6 @@ router.get(`${config.site_path}/atom`, (req,res) => {
// user ATOM protocol gets
router.get(`${config.site_path}/user/:username/atom`, (req,res) => {
const username = req.params.username;
- const userID = func.get_userID(username);
if (config.atom == false) {
res.render("partials/message", {
message: locale.atom_disabled,
@@ -75,11 +76,10 @@ router.get(`${config.site_path}/user/:username/atom`, (req,res) => {
}
else {
res.setHeader('content-type', 'application/rss+xml');
- res.render("syndication/user_atom", {
+ res.render("syndication/atom", {
config,
posts: data.getdata('posts'),
func,
- userID,
getUnixTime,
})
};
diff --git a/views/syndication/atom.ejs b/views/syndication/atom.ejs
new file mode 100644
index 0000000..b23dd72
--- /dev/null
+++ b/views/syndication/atom.ejs
@@ -0,0 +1,22 @@
+" ?>
+
+ <%= config.site_name %>
+ <%= config.site_url %>
+ <%= config.site_description %>
+ <%= func.unix_time_to_date_format(getUnixTime(new Date()),"yyyy-MM-dd'T'HH:mm:ss'Z'") %>
+ <%= config.site_url %>
+ <% for (let postID = posts.length-1; postID >= 0; postID--) { %>
+ <% if (posts[postID]["deleted"] != true) { %>
+
+ <%= posts[postID]["title"] %>
+ <%= config.site_url %>/post/<%= postID %>
+ ]]>
+ <%= config.site_url %>/post/<%= postID %>
+ <%# func.unix_time_to_date_format(posts[postID]['pubdate'],"yyyy-MM-dd'T'HH:mm:ss'Z'") %>
+ <% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
+ ]]>
+ <% } %>
+
+ <% } %>
+ <% } %>
+
diff --git a/views/syndication/rss.ejs b/views/syndication/rss.ejs
index bdb0ea0..0f0aaa3 100644
--- a/views/syndication/rss.ejs
+++ b/views/syndication/rss.ejs
@@ -1,22 +1,23 @@
" ?>
-
- <%= config.site_name %>
- <%= config.site_url %>
- <%= config.site_description %>
- <% for (let postID = posts.length-1; postID >= 0; postID--) { %>
- <% if (posts[postID]["deleted"] != true) { %>
- -
- <%= posts[postID]["title"] %>
- <%= config.site_url %>/post/<%= postID %>
- ]]>
- <%= config.site_url %>/post/<%= postID %>
- <%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %>
- <% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
- ]]>
- <% } %>
-
- <% } %>
- <% } %>
-
+
+ <%= config.site_name %>
+ <%= config.site_url %>
+ <%= config.site_description %>
+ <% for (let postID = posts.length-1; postID >= 0; postID--) { %>
+ <% if (posts[postID]["deleted"] != true) { %>
+ -
+ <%= posts[postID]["title"] %>
+ <%= config.site_url %>/post/<%= postID %>
+ ]]>
+ <%= config.site_url %>/post/<%= postID %>
+ <%= func.unix_time_to_date_format(posts[postID]['pubdate'],'EEE, dd MMM yyyy HH:mm:ss') %>
+ <%= users[posts[postID]['userID']]['prettyname'] %>
+ <% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
+ ]]>
+ <% } %>
+
+ <% } %>
+ <% } %>
+