Database reading changes should work, gotta implement same for writing and finish up testing then merge back into master
This commit is contained in:
@@ -14,7 +14,7 @@ export function increment_hitcount(postID = -1) { // -1 Means it will increment
|
|||||||
writedata('hitcount', hitcount);
|
writedata('hitcount', hitcount);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let post = getdata('posts','id', postID);
|
let post = getdata('posts','id', postID)[0];
|
||||||
if (post == 1) // Does not exist
|
if (post == 1) // Does not exist
|
||||||
{
|
{
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
@@ -75,24 +75,6 @@ export function render_tags(tags_string)
|
|||||||
}
|
}
|
||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
// The users are stored as a list of objects [ user_object, user_object, user_object ]
|
|
||||||
// So you cannot easily find the userID (position in list) from the username
|
|
||||||
// This function returns the username for a given userID by looping over every user
|
|
||||||
// if the user is present, it returns the index of the user (integer)
|
|
||||||
// if the user is not present it returns -1
|
|
||||||
export function get_userID(username)
|
|
||||||
{
|
|
||||||
const users = require_module("../data/users.json")
|
|
||||||
for (let i = 0; i < users.length; i++)
|
|
||||||
{ // Loop over every user
|
|
||||||
if (users[i]['username'] == username)
|
|
||||||
{
|
|
||||||
return i // If the username matches then return the index of that user
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1 // If user is not present, return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
// This escapes some potentially dangerous HTML characters with their HTML entities
|
// This escapes some potentially dangerous HTML characters with their HTML entities
|
||||||
// https://www.freeformatter.com/html-entities.html
|
// https://www.freeformatter.com/html-entities.html
|
||||||
// accepts a string
|
// accepts a string
|
||||||
@@ -146,8 +128,7 @@ export function find_key_value_pair(data_array, key, value) {
|
|||||||
let return_list = []
|
let return_list = []
|
||||||
for (let i = 0; i < data_array.length; i++) {
|
for (let i = 0; i < data_array.length; i++) {
|
||||||
let element = data_array[i][key]
|
let element = data_array[i][key]
|
||||||
if (element == value
|
if (element == value || (key == 'tags' && element.includes(value))) {
|
||||||
|| (Array.isArray(element) && element.includes(value))) {
|
|
||||||
return_list.push(data_array[i])
|
return_list.push(data_array[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,16 +33,14 @@ router.get("/", (req,res) => {
|
|||||||
|
|
||||||
// Users
|
// Users
|
||||||
router.get("/user/:username", (req, res) => {
|
router.get("/user/:username", (req, res) => {
|
||||||
const userID = func.get_userID(req.params.username)
|
let user = data.getdata('users', 'username', req.params.username)
|
||||||
let user = data.getdata('users', 'id', userID)[0]
|
if (user.length > 0) {
|
||||||
if (userID != -1) {
|
|
||||||
res.render("pages/user",
|
res.render("pages/user",
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
locale,
|
locale,
|
||||||
posts: data.getdata('posts'),
|
posts: data.getdata('posts','userID',user[0].id),
|
||||||
user,
|
user: user[0],
|
||||||
userID: userID,
|
|
||||||
comments: data.getdata('comments'),
|
comments: data.getdata('comments'),
|
||||||
fromUnixTime,
|
fromUnixTime,
|
||||||
format,
|
format,
|
||||||
@@ -50,7 +48,7 @@ router.get("/user/:username", (req, res) => {
|
|||||||
func,
|
func,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else if (userID == -1) {
|
else {
|
||||||
res.render("partials/message",
|
res.render("partials/message",
|
||||||
{
|
{
|
||||||
message: locale.user_doesnt_exist,
|
message: locale.user_doesnt_exist,
|
||||||
@@ -79,8 +77,8 @@ router.get("/post/:post_index", (req, res) => {
|
|||||||
locale,
|
locale,
|
||||||
post,
|
post,
|
||||||
postID,
|
postID,
|
||||||
user: data.getdata('users','id', post.userID),
|
user: data.getdata('users','id', post.userID)[0],
|
||||||
comments: data.getdata('comments','id', postID)["comments"],
|
comments: data.getdata('comments','id', postID)[0]["comments"],
|
||||||
fromUnixTime,
|
fromUnixTime,
|
||||||
format,
|
format,
|
||||||
getUnixTime,
|
getUnixTime,
|
||||||
@@ -93,19 +91,23 @@ router.get("/post/:post_index", (req, res) => {
|
|||||||
// Tags
|
// Tags
|
||||||
router.get("/tag/:tag", (req,res) => {
|
router.get("/tag/:tag", (req,res) => {
|
||||||
const tag = req.params.tag
|
const tag = req.params.tag
|
||||||
|
const posts = data.getdata('posts','tags',tag);
|
||||||
|
console.log(posts)
|
||||||
|
const users = data.getdata('users')
|
||||||
|
const comments = data.getdata('comments')
|
||||||
res.render("pages/tag",
|
res.render("pages/tag",
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
locale,
|
locale,
|
||||||
tag,
|
tag,
|
||||||
posts: data.getdata('posts'),
|
posts,
|
||||||
users: data.getdata('users'),
|
users,
|
||||||
comments: data.getdata('comments'),
|
comments,
|
||||||
fromUnixTime,
|
fromUnixTime,
|
||||||
format,
|
format,
|
||||||
getUnixTime,
|
getUnixTime,
|
||||||
func,
|
func,
|
||||||
})
|
})
|
||||||
}); // /tag/:tag
|
}); // /tag/:tag
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<p><%- func.render_md(user.description) %></p>
|
<p><%- func.render_md(user.description) %></p>
|
||||||
<a if='edit-account-link' href="<%= config.edit_account_base_url %>/<%= userID %>">
|
<a if='edit-account-link' href="<%= config.edit_account_base_url %>/<%= user.id %>">
|
||||||
<img class='icon' src='/icons/edit.png' alt='<%= locale.edit_account %>' title='<%= locale.edit_account %>'>
|
<img class='icon' src='/icons/edit.png' alt='<%= locale.edit_account %>' title='<%= locale.edit_account %>'>
|
||||||
</a>
|
</a>
|
||||||
|
|
|
|
||||||
|
|||||||
@@ -12,13 +12,7 @@
|
|||||||
</header>
|
</header>
|
||||||
<div id="posts">
|
<div id="posts">
|
||||||
<% for (let index = posts.length - 1; index >= 0; index--) { %>
|
<% for (let index = posts.length - 1; index >= 0; index--) { %>
|
||||||
<% if ( posts[index].deleted != true) { %>
|
<%- include('../posts/tag', {post: posts[index], postID: index, user: users[posts[index].userID], comments: comments[index]}); %>
|
||||||
<% posts[index].tags.forEach((current_tag, tag_index) => { %>
|
|
||||||
<% if (current_tag.toLowerCase() == tag.toLowerCase()) { %>
|
|
||||||
<%- include('../posts/tag', {post: posts[index], postID: index, user: users[posts[index].userID], comments: comments[index]}); %>
|
|
||||||
<% } %>
|
|
||||||
<% }) %>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<footer id='footer'>
|
<footer id='footer'>
|
||||||
|
|||||||
@@ -12,9 +12,7 @@
|
|||||||
</header>
|
</header>
|
||||||
<div id="posts">
|
<div id="posts">
|
||||||
<% for (let index = posts.length - 1; index >= 0; index--) { %>
|
<% for (let index = posts.length - 1; index >= 0; index--) { %>
|
||||||
<% if (posts[index].userID == userID) { %>
|
<%- include('../posts/user', {post: posts[index], postID: index, user: user, comments: comments[index]}); %>
|
||||||
<%- include('../posts/user', {post: posts[index], postID: index, user: user, comments: comments[index]}); %>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
<footer id='footer'>
|
<footer id='footer'>
|
||||||
|
|||||||
23
views/syndication/atom.ejs
Normal file
23
views/syndication/atom.ejs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
||||||
|
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||||
|
<title><%= config.site_name %></title>
|
||||||
|
<link><%= config.site_url %></title>
|
||||||
|
<description><%= config.site_description %></description>
|
||||||
|
<updated><%= func.unix_time_to_date_format(getUnixTime(new Date()),"yyyy-MM-dd'T'HH:mm:ss'Z'") %></updated>
|
||||||
|
<id><%= config.site_url %></id>
|
||||||
|
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||||
|
<% if (posts[postID]["deleted"] != true) { %>
|
||||||
|
<entry>
|
||||||
|
<title><%= posts[postID]["title"] %></title>
|
||||||
|
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||||
|
<summary><![CDATA[<%- (posts[postID]["content"]) %>]]></summary>
|
||||||
|
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||||
|
<pubDate><%- func.unix_time_to_date_format(posts[postID]['pubdate'],"yyyy-MM-dd'T'HH:mm:ss'Z'") %></pubDate>
|
||||||
|
<% tags = posts[postID]['tags'].split(',') %>
|
||||||
|
<% for (let tag_index = 0; tag_index < tags.length; tag_index++) { %>
|
||||||
|
<category><![CDATA[<%= tags[tag_index] %>]]></category>
|
||||||
|
<% } %>
|
||||||
|
</entry>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
</feed>
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
||||||
<title><%= config.site_name %></title>
|
|
||||||
<link><%= config.site_url %></link>
|
|
||||||
<description><%= config.site_description %></description>
|
|
||||||
<updated><%= func.unix_time_to_atom_date(getUnixTime(new Date())) %></updated>
|
|
||||||
<id><%= config.site_url %></id>
|
|
||||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
|
||||||
<% if (posts[postID]["deleted"] != true) { %>
|
|
||||||
<entry>
|
|
||||||
<title><%= posts[postID]["title"] %></title>
|
|
||||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
|
||||||
<summary><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></summary>
|
|
||||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
|
||||||
<pubDate><%# func.unix_time_to_atom_date(posts[postID]['pubdate']) %></pubDate>
|
|
||||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
|
||||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
|
||||||
<% } %>
|
|
||||||
</entry>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
</feed>
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
|
||||||
<rss version="2.0">
|
|
||||||
<channel>
|
|
||||||
<title><%= config.site_name %></title>
|
|
||||||
<link><%= config.site_url %></link>
|
|
||||||
<description><%= config.site_description %></description>
|
|
||||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
|
||||||
<% if (posts[postID]["deleted"] != true) { %>
|
|
||||||
<item>
|
|
||||||
<title><%= posts[postID]["title"] %></title>
|
|
||||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
|
||||||
<description><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></description>
|
|
||||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
|
||||||
<pubDate><%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %></pubDate>
|
|
||||||
<author><%= users[posts[postID]['userID']]['prettyname'] %></author>
|
|
||||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
|
||||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
|
||||||
<% } %>
|
|
||||||
</item>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
</channel>
|
|
||||||
</rss>
|
|
||||||
23
views/syndication/rss.ejs
Normal file
23
views/syndication/rss.ejs
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<rss version="2.0">
|
||||||
|
<channel>
|
||||||
|
<title><%= config.site_name %></title>
|
||||||
|
<link><%= config.site_url %></link>
|
||||||
|
<description><%= config.site_description %></description>
|
||||||
|
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||||
|
<% if (posts[postID]["deleted"] != true) { %>
|
||||||
|
<item>
|
||||||
|
<title><%= posts[postID]["title"] %></title>
|
||||||
|
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||||
|
<description><![CDATA[<%- (posts[postID]["content"]) %>]]></description>
|
||||||
|
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||||
|
<pubDate><%= func.unix_time_to_date_format(posts[postID]['pubdate'],'EEE, dd MMM yyyy HH:mm:ss') %></pubDate>
|
||||||
|
<author><%= users[posts[postID]['userID']]['prettyname'] %></author>
|
||||||
|
<% tags = posts[postID]['tags'].split(',') %>
|
||||||
|
<% for (let tag_index = 0; tag_index < tags.length; tag_index++) { %>
|
||||||
|
<category><![CDATA[<%= tags[tag_index] %>]]></category>
|
||||||
|
<% } %>
|
||||||
|
</item>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
|
||||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
|
||||||
<title><%= config.site_name %></title>
|
|
||||||
<link><%= config.site_url %></title>
|
|
||||||
<description><%= config.site_description %></description>
|
|
||||||
<updated><%= func.unix_time_to_atom_date(getUnixTime(new Date())) %></updated>
|
|
||||||
<id><%= config.site_url %></id>
|
|
||||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
|
||||||
<% if (posts[postID]["userID"] == userID) { %>
|
|
||||||
<% if (posts[postID]["deleted"] != true) { %>
|
|
||||||
<entry>
|
|
||||||
<title><%= posts[postID]["title"] %></title>
|
|
||||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
|
||||||
<summary><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></summary>
|
|
||||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
|
||||||
<pubDate><%# func.unix_time_to_atom_date(posts[postID]['pubdate']) %></pubDate>
|
|
||||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
|
||||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
|
||||||
<% } %>
|
|
||||||
</entry>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
</feed>
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
|
||||||
<rss version="2.0">
|
|
||||||
<channel>
|
|
||||||
<title><%= config.site_name %></title>
|
|
||||||
<link><%= config.site_url %></title>
|
|
||||||
<description><%= config.site_description %></description>
|
|
||||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
|
||||||
<% if (posts[postID]["userID"] == userID) { %>
|
|
||||||
<% if (posts[postID]["deleted"] != true) { %>
|
|
||||||
<item>
|
|
||||||
<title><%= posts[postID]["title"] %></title>
|
|
||||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
|
||||||
<description><![CDATA[<%- func.render_md(posts[postID]["content"]) %>]]></description>
|
|
||||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
|
||||||
<pubDate><%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %></pubDate>
|
|
||||||
<author><%= users[posts[postID]['userID']]['prettyname'] %></author>
|
|
||||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
|
||||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
|
||||||
<% } %>
|
|
||||||
</item>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
<% } %>
|
|
||||||
</channel>
|
|
||||||
</rss>
|
|
||||||
Reference in New Issue
Block a user