Compare commits
61 Commits
d75a74b7a8
...
master
Author | SHA1 | Date | |
---|---|---|---|
e3e5469e1a | |||
c8af978259 | |||
99e07389d0 | |||
532010f873 | |||
5917789c5b | |||
4f0941262e | |||
27b9ee6437 | |||
c73ce69f93 | |||
5bd0429ae2 | |||
6e583d1410 | |||
cf784a1a99 | |||
b3ea048244 | |||
9b5d3f3f73 | |||
5f07db1e15 | |||
d298717519 | |||
0b25fb221b | |||
f85c4aa893 | |||
6fc1f85e18 | |||
8418318d80 | |||
44a060508b | |||
49c7fc7cdf | |||
144c276bc9 | |||
df4bc99d9a | |||
3e2a63bfd7 | |||
bced9c7c0e | |||
f723e37732 | |||
8b9ddcf048 | |||
5f2aba0c2b | |||
cdfc5f2c30 | |||
88b198365d | |||
b683b658f7 | |||
0cc319a702 | |||
72316094e4 | |||
47877e71d4 | |||
0c43c7315c | |||
39eba8fcda | |||
38d82f9e1a | |||
bb62ccf25f | |||
40e0cc80a3 | |||
306adf3943 | |||
ff1d34a7ab | |||
797d894621 | |||
929151a16d | |||
ce93a1991b | |||
cc131798a3 | |||
7eeafddae4 | |||
fc3a68e476 | |||
590d675075 | |||
d54b682267 | |||
2dfed40665 | |||
3e745e6842 | |||
74f2e4eaec | |||
636a460918 | |||
b5ab7af515 | |||
9a1bc97b99 | |||
09ab903815 | |||
0b70624e05 | |||
23685d02c0 | |||
3efe4b7836 | |||
4fb12c54f8 | |||
3a821b5eba |
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,7 +1,9 @@
|
|||||||
node_modules
|
node_modules
|
||||||
package-lock.json
|
package-lock.json
|
||||||
posts.js
|
posts.json
|
||||||
comments.js
|
comments.json
|
||||||
users.js
|
users.json
|
||||||
config.js
|
config.json
|
||||||
|
hitcount.txt
|
||||||
*.swp
|
*.swp
|
||||||
|
webroot/
|
||||||
|
57
README.md
57
README.md
@@ -1,24 +1,51 @@
|
|||||||
This is a blogging site written in nodejs, all pages are served directly by the nodejs backend.<br/>
|
This software aims to provide a lot of power to the web admin who is running the blog site.<br/>
|
||||||
Please don't use this yet, it's not finished<br/>
|
Customisation is unlimited with a bit of knowledge of EJS and CSS, you can edit the entire formatting of the pages, making the site truly yours!<br/>
|
||||||
In action on my website: [deadvey.com](https://deadvey.com)<br/>
|
This software also aims to be compatible with text based browsers and as a result contains no client side Javascript, if you're looking for a more<br/>
|
||||||
|
beautiful and featureful blogging frontend, this isn't for you.<br/>
|
||||||
|
|
||||||
# features
|
> [!CAUTION]
|
||||||
* post creation via the web frontend (no need to remote to your server to make a post)
|
> This software is not finished yet, so it's very buggy and probably really insecure<br/>
|
||||||
|
> use at your own risk!<br/>
|
||||||
|
|
||||||
|
See the software in action: [deadvey.com](https://deadvey.com)<br/>
|
||||||
|
|
||||||
|
# Installation and Running:
|
||||||
|
Read the [installation guide](/docs/INSTALLATION.md)
|
||||||
|
|
||||||
|
# Confiuration:
|
||||||
|
Read the [configuation guide](docs/CONFIG.md) for configuration help (in config.json)
|
||||||
|
|
||||||
|
# Features:
|
||||||
|
* post creation, modification and deletion via frontend
|
||||||
|
* user creation, modification and deletion via frontend
|
||||||
* multi user
|
* multi user
|
||||||
* powerful customisation
|
* powerful customisation via EJS
|
||||||
* rss
|
* site wide and user specific rss, atom
|
||||||
* timeline, user page, post page and tag specific page
|
|
||||||
* edit/delete posts
|
|
||||||
* hitcount
|
* hitcount
|
||||||
* Markdown syntax in posts
|
* Markdown syntax in posts
|
||||||
* Commenting on posts
|
* Commenting on posts and replying to other comments
|
||||||
|
* site wide custom CSS
|
||||||
|
* Page indexes
|
||||||
|
|
||||||
# Bugs
|
# Bugs:
|
||||||
* probably scales like shit
|
* probably scales like shit
|
||||||
* probably insecure as hell
|
* probably insecure as hell
|
||||||
|
|
||||||
# planned features
|
# Planned features/todo list:
|
||||||
* atom
|
* federation (looks tricky)
|
||||||
* federation
|
|
||||||
* sign up
|
|
||||||
* All strings (including in edit and post page) customisable
|
* All strings (including in edit and post page) customisable
|
||||||
|
* formatable custom strings
|
||||||
|
* inline comments and docs
|
||||||
|
* clean up code a bit
|
||||||
|
* /postID and /userID pages
|
||||||
|
* site index
|
||||||
|
* Make EJS modification more user friendly
|
||||||
|
* API for returning posts, users, comments, tags other?...
|
||||||
|
|
||||||
|
# Docs:
|
||||||
|
See [docs/DOCUMENTATION.md](docs/DOCUMENTATION.md)
|
||||||
|
|
||||||
|
# Customisation:
|
||||||
|
Customisation of settings can be done via the config.json file (use example-config.json as an example) and see [the configuration guide](docs/CONFIG.md)<br/>
|
||||||
|
Additionaly, more complex configuration of the precise template of the whole site, can be done via [EJS](https://ejs.co/) (in /views) (see [the list of things variables and functions available in EJS](docs/EJS.md) (you will need to understand EJS syntax and JavaScript, to customise this (why did I use EJS? well I originally had this weird system of format indicators with percent (%) signs and stuff (like in unix's date (`date`)) but then I was told EJS is better and it sure is, though it is a bit harder to understand but MUCH more powerful!))
|
||||||
|
Also, if you want to change any of the strings on the website, please modify or create a new, customised locale in /locales
|
||||||
|
372
app.js
372
app.js
@@ -1,372 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const express = require('express');
|
|
||||||
const showdown = require('showdown')
|
|
||||||
const crypto = require('crypto'); // For encrypting passwords
|
|
||||||
const { fromUnixTime, format, getUnixTime } = require("date-fns")
|
|
||||||
|
|
||||||
if (process.argv[2] == "--first-time") {
|
|
||||||
initialise()
|
|
||||||
}
|
|
||||||
|
|
||||||
let users
|
|
||||||
let posts
|
|
||||||
let comments
|
|
||||||
let config
|
|
||||||
|
|
||||||
try {
|
|
||||||
users = require('./users.js');
|
|
||||||
posts = require('./posts.js');
|
|
||||||
comments = require('./comments.js');
|
|
||||||
config = require('./config.js');
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.log("A file is missing!")
|
|
||||||
console.log("Run with --first-time to initialise the program")
|
|
||||||
console.log(error)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
let converter = new showdown.Converter({
|
|
||||||
simpleLineBreaks: true,
|
|
||||||
tables: true,
|
|
||||||
strikethrough: true,
|
|
||||||
tasklists: true,
|
|
||||||
encodeEmails: true
|
|
||||||
})
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
let footer_div = config.site_wide_footer
|
|
||||||
footer_div = replace_format_indicators(footer_div)
|
|
||||||
|
|
||||||
app.use(express.urlencoded({ extended: true }));
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.static(config.root_path));
|
|
||||||
|
|
||||||
function initialise() {
|
|
||||||
try {
|
|
||||||
const users = require("./users.js");
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.log("Creating users file")
|
|
||||||
fs.writeFileSync(`${__dirname}/users.js`, `export const users = []`)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const posts = require("./posts.js");
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.log("Creating posts file")
|
|
||||||
fs.writeFileSync(`${__dirname}/posts.js`, `export const posts = []`)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const comments = require("./comments.js");
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.log("Creating comments file")
|
|
||||||
fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = []\nexport const counter = 0`)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const config = require("./config.js");
|
|
||||||
}
|
|
||||||
catch (error) {
|
|
||||||
console.log("Copying the example config to config.js")
|
|
||||||
console.log("!!! PLEASE MODIFY config.js TO YOUR NEEDS !!!")
|
|
||||||
fs.copyFile('example-config.js', 'config.js', (err) => {
|
|
||||||
console.log("Error copying file")
|
|
||||||
})
|
|
||||||
}
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_userID(username) {
|
|
||||||
for (let i = 0; i < users.users.length; i++) {
|
|
||||||
if (users.users[i]['username'] == username) {
|
|
||||||
return i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
function unix_time_to_date_format(unix_time) {
|
|
||||||
date = fromUnixTime(unix_time)
|
|
||||||
formatted_date = format(date, config.date_format)
|
|
||||||
|
|
||||||
return formatted_date
|
|
||||||
}
|
|
||||||
|
|
||||||
function unix_time_to_rss_date(unix_time) {
|
|
||||||
date = fromUnixTime(unix_time)
|
|
||||||
formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss")
|
|
||||||
return `${formatted_date} ${config.time_zone}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function hyperlink_tags(tags) {
|
|
||||||
string = ""
|
|
||||||
for (let tag_index = 0; tag_index < tags.length; tag_index++) {
|
|
||||||
string += `<a href="/tag/${tags[tag_index]}">${tags[tag_index]}</a>`
|
|
||||||
if (tag_index < tags.length - 1) {
|
|
||||||
string += ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return string
|
|
||||||
}
|
|
||||||
|
|
||||||
function replace_format_indicators(input_string, post_index=0, tag_name="tag") {
|
|
||||||
post_object = posts.posts[post_index]
|
|
||||||
output_string = input_string
|
|
||||||
.replaceAll("%%", "%")
|
|
||||||
.replaceAll("%A", (post_object["tags"]))
|
|
||||||
.replaceAll("%B", (hyperlink_tags(post_object["tags"])))
|
|
||||||
.replaceAll("%C", converter.makeHtml(post_object["content"]))
|
|
||||||
.replaceAll("%D", unix_time_to_date_format(post_object["pubdate"]))
|
|
||||||
.replaceAll("%E", unix_time_to_date_format(post_object["editdate"]))
|
|
||||||
.replaceAll("%F", users.users[post_object["userID"]]['prettyname'])
|
|
||||||
.replaceAll("%G", tag_name)
|
|
||||||
.replaceAll("%I", users.users[post_object['userID']]['description'])
|
|
||||||
.replaceAll("%L", `/post/${post_index}`)
|
|
||||||
.replaceAll("%M", return_comments(post_index))
|
|
||||||
.replaceAll("%N", users.users[post_object["userID"]]['username'])
|
|
||||||
.replaceAll("%P", "/post")
|
|
||||||
.replaceAll("%O", `/edit/${post_index}`)
|
|
||||||
.replaceAll("%R", "/rss")
|
|
||||||
.replaceAll("%S", config.seperator)
|
|
||||||
.replaceAll("%T", post_object["title"])
|
|
||||||
.replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`)
|
|
||||||
.replaceAll("%X", `<form method="POST" action="/submit_comment">
|
|
||||||
<input type="hidden" name="post_index" value="${post_index}">
|
|
||||||
<input placeholder="username" name="name"><br/>
|
|
||||||
<textarea placeholder="comment" name="content"></textarea><br/>
|
|
||||||
<button type="submit">Submit</button>
|
|
||||||
</form>`)
|
|
||||||
.replaceAll("%Y", config.site_name)
|
|
||||||
.replaceAll("%W", config.site_description)
|
|
||||||
.replaceAll("%Z", config.attribution)
|
|
||||||
if (config.enable_hitcount == true) {
|
|
||||||
output_string = output_string
|
|
||||||
.replaceAll("%H", fs.readFileSync('hitcount.txt'))
|
|
||||||
}
|
|
||||||
|
|
||||||
return output_string
|
|
||||||
}
|
|
||||||
|
|
||||||
function escape_input(input) {
|
|
||||||
let output = input
|
|
||||||
.replaceAll("<", "<")
|
|
||||||
.replaceAll(">", ">")
|
|
||||||
.replaceAll("\\", "\")
|
|
||||||
.replaceAll('"', """)
|
|
||||||
.replaceAll("'", "'")
|
|
||||||
.replaceAll("/", "/")
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO make the formatting customisable
|
|
||||||
function return_comments(post_id) {
|
|
||||||
const post_comments = comments.comments[post_id]
|
|
||||||
let comment_content = ""
|
|
||||||
for (let comment_index = 0; comment_index < post_comments.length; comment_index++) {
|
|
||||||
let comment = {...post_comments[comment_index]};
|
|
||||||
comment['content'] = comment['content']
|
|
||||||
.replaceAll(/>> ([0-9]*)/g, "<a href='#$1'>>> $1</a>")
|
|
||||||
.replaceAll("\n", "<br/>")
|
|
||||||
comment_content += `<div id="${comment['id']}">${comment['name']} ${unix_time_to_date_format(comment['pubdate'])} No. ${comment['id']}<br/>${comment['content']}</div><br/>`
|
|
||||||
}
|
|
||||||
return comment_content
|
|
||||||
}
|
|
||||||
|
|
||||||
// RSS protocol gets
|
|
||||||
app.get(config.rss_path, (req,res) => {
|
|
||||||
if (config.rss == false) {
|
|
||||||
res.send("Sorry, RSS is disabled!")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let rss_content = `<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<rss version="2.0">
|
|
||||||
<channel>
|
|
||||||
<title>${config.site_name}</title>
|
|
||||||
<link>${config.site_url}</link>
|
|
||||||
<description>${config.site_description}</description>
|
|
||||||
`
|
|
||||||
for (let i = posts.posts.length-1; i >= 0; i--) {
|
|
||||||
rss_content += `
|
|
||||||
<item>
|
|
||||||
<title>${posts.posts[i]["title"]}</title>
|
|
||||||
<link>${config.site_url}/post/${i}</link>
|
|
||||||
<description><![CDATA[${converter.makeHtml(posts.posts[i]["content"])}]]></description>
|
|
||||||
<guid isPermaLink="true">${config.site_url}/post/${i}</guid>
|
|
||||||
<pubDate>${unix_time_to_rss_date(posts.posts[i]['pubdate'])}</pubDate>`
|
|
||||||
for (let j = 0; j < posts.posts[i]['tags'].length; j++) {
|
|
||||||
rss_content += `<category><![CDATA[${posts.posts[i]['tags'][j]}]]></category>`
|
|
||||||
};
|
|
||||||
rss_content += "</item>"
|
|
||||||
}
|
|
||||||
rss_content += `
|
|
||||||
</channel>
|
|
||||||
</rss>`
|
|
||||||
res.setHeader('content-type', 'application/rss+xml');
|
|
||||||
res.send(rss_content)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/", (req,res) => {
|
|
||||||
if (config.enable_hitcount) {
|
|
||||||
let hitcount = parseInt(fs.readFileSync('hitcount.txt'))
|
|
||||||
hitcount += 1
|
|
||||||
console.log(`/ Is loaded, hitcount: ${hitcount}`)
|
|
||||||
fs.writeFileSync(`${__dirname}/hitcount.txt`, `${hitcount}`, 'utf-8');
|
|
||||||
}
|
|
||||||
|
|
||||||
header_div = config.timeline_header
|
|
||||||
header_div = replace_format_indicators(header_div);
|
|
||||||
posts_div = "";
|
|
||||||
counter = posts.posts.length - 1;
|
|
||||||
while ((counter >= 0) && (counter > (posts.posts.length - (config.timeline_length + 1))))
|
|
||||||
{
|
|
||||||
let post = config.timeline_post_format;
|
|
||||||
posts_div += replace_format_indicators(post, counter);
|
|
||||||
counter -= 1;
|
|
||||||
}
|
|
||||||
res.send(`<html><head><meta charset="${config.charset}"><style>${config.css}</style></head><body><div id="header">${header_div}</div><div id="posts">${posts_div}</div></body><footer>${footer_div}</footer></html>`);
|
|
||||||
});
|
|
||||||
app.get("/user/:username", (req, res) => {
|
|
||||||
header_div = config.user_page_header
|
|
||||||
header_div = replace_format_indicators(header_div)
|
|
||||||
posts_div = "";
|
|
||||||
for (let post_index = posts.posts.length-1; post_index >= 0; post_index--) {
|
|
||||||
if (users.users[posts.posts[post_index]["userID"]]["username"] == req.params.username) {
|
|
||||||
let post = config.user_post_format;
|
|
||||||
posts_div += replace_format_indicators(post, post_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res.send(`<html><head><meta charset="${config.charset}"><style>${config.css}</style></head><body><div id="header">${header_div}</div><div id="posts">${posts_div}</div></body><footer>${footer_div}</footer></html>`);
|
|
||||||
});
|
|
||||||
app.get("/post/:post_index", (req, res) => {
|
|
||||||
post_div = "";
|
|
||||||
let post = config.post_page_format;
|
|
||||||
post_div += replace_format_indicators(post, req.params.post_index);
|
|
||||||
res.send(`<html><head><meta charset="${config.charset}"><style>${config.css}</style></head><body><div id="posts">${post_div}</div></body><footer>${footer_div}</footer></html>`);
|
|
||||||
});
|
|
||||||
app.get("/tag/:tag", (req,res) => {
|
|
||||||
const tag = req.params.tag
|
|
||||||
let header_div = config.tag_page_header
|
|
||||||
header_div = replace_format_indicators(header_div,0,tag)
|
|
||||||
let page_content = ""
|
|
||||||
for (let i = posts.posts.length-1; i >= 0; i--) {
|
|
||||||
if (posts.posts[i]['tags'].includes(tag)) {
|
|
||||||
let post = config.tag_post_format;
|
|
||||||
page_content += replace_format_indicators(post, i);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
res.send(`<html><style>${config.css}</style><body><div id="header">${header_div}</div><div id="posts">${page_content}</div></body><footer>${footer_div}</footer></html>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get("/post", (req,res) => {
|
|
||||||
res.send(`</html><head><meta charset="${config.charset}"><style>${config.css}</style></head><form action="/submit_post" method="POST">
|
|
||||||
<input placeholder="username" required name="username"><br/>
|
|
||||||
<input placeholder="password" type="password" required id="password" name="password"><br/>
|
|
||||||
<input placeholder="title" required name="title"><br/>
|
|
||||||
<textarea placeholder="post content*" required name="content"></textarea><br/>
|
|
||||||
<input placeholder="Tags (comma seperated)" name="tags"><br/>
|
|
||||||
<input type="submit" value="Submit"><br/>
|
|
||||||
<small>* Markdown supported</small>
|
|
||||||
</form></html>`);
|
|
||||||
});
|
|
||||||
app.get("/edit/:post_id", (req,res) => {
|
|
||||||
const post_id = req.params.post_id
|
|
||||||
const post = posts.posts[post_id]
|
|
||||||
const user = users.users[post['userID']]
|
|
||||||
res.send(`</html><head><meta charset="${config.charset}"><style>${config.css}</style></head>
|
|
||||||
<form action="/submit_edit" method="POST" onsubmit="sha512password()">
|
|
||||||
<input name="userID" type="hidden" value="${post['userID']}">
|
|
||||||
<input name="postID" type="hidden" value="${post_id}">
|
|
||||||
<input placeholder="${user['prettyname']}'s password" type="password" required id="password" name="password"><br/>
|
|
||||||
<input placeholder="title" value="${post['title']}" required name="title"><br/>
|
|
||||||
<textarea placeholder="content" required name="content">${post['content']}</textarea><br/>
|
|
||||||
<input placeholder="tags (comma seperated)" value="${post['tags']}" name="tags"><br/>
|
|
||||||
<label>Delete forever (no undo): </label><input name="delete" type="checkbox"><br/>
|
|
||||||
<input type="submit" value="Submit"><br/>
|
|
||||||
<small>* Markdown supported</small>
|
|
||||||
</form></html>`);
|
|
||||||
});
|
|
||||||
|
|
||||||
app.post("/submit_comment", (req,res) => {
|
|
||||||
const unix_timestamp = getUnixTime(new Date())
|
|
||||||
let name = escape_input(req.body.name)
|
|
||||||
if (name == "") {
|
|
||||||
name = config.default_username
|
|
||||||
}
|
|
||||||
new_comment = {
|
|
||||||
"name": name,
|
|
||||||
"content": escape_input(req.body.content),
|
|
||||||
"id": comments.counter,
|
|
||||||
"pubdate": unix_timestamp
|
|
||||||
};
|
|
||||||
let counter = comments.counter+1;
|
|
||||||
comments.comments[req.body.post_index].push(new_comment);
|
|
||||||
fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = ${JSON.stringify(comments.comments)}\nexport const counter = ${counter}`, 'utf-8');
|
|
||||||
|
|
||||||
res.redirect(301,`/post/${req.body.post_index}`)
|
|
||||||
});
|
|
||||||
app.post("/submit_edit", (req,res) => {
|
|
||||||
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
|
|
||||||
const postID = req.body.postID
|
|
||||||
const userID = req.body.userID
|
|
||||||
const title = req.body.title
|
|
||||||
const content = req.body.content
|
|
||||||
const tags = req.body.tags.split(',');
|
|
||||||
const delete_bool = req.body.delete
|
|
||||||
const unix_timestamp = getUnixTime(new Date())
|
|
||||||
console.log(users.users[userID]['prettyname'], "is editting the post titled:", title);
|
|
||||||
|
|
||||||
if (users.users[userID]['hash'] == password) { // password matches
|
|
||||||
let post = posts.posts[postID]
|
|
||||||
post['title'] = title
|
|
||||||
post['content'] = content
|
|
||||||
post['tags'] = tags
|
|
||||||
post['editdate'] = unix_timestamp
|
|
||||||
if (typeof delete_bool != "undefined") {
|
|
||||||
console.log("Deleting post!")
|
|
||||||
posts.posts.splice(postID,1)
|
|
||||||
comments.comments.splice(postID,1)
|
|
||||||
fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = ${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`, 'utf-8');
|
|
||||||
}
|
|
||||||
fs.writeFileSync(`${__dirname}/posts.js`, `export const posts = ${JSON.stringify(posts.posts)}`, 'utf-8');
|
|
||||||
res.redirect(302, "/");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.send(`Invalid Password for user`,users.users[userID]['prettyname']);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
app.post("/submit_post", (req,res) => {
|
|
||||||
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
|
|
||||||
const username = escape_input(req.body.username)
|
|
||||||
const title = escape_input(req.body.title)
|
|
||||||
const content = escape_input(req.body.content)
|
|
||||||
const tags = escape_input(req.body.tags).split(',');
|
|
||||||
const unix_timestamp = getUnixTime(new Date())
|
|
||||||
console.log(username, "is submitting a post titled:", title);
|
|
||||||
|
|
||||||
if (get_userID(username) == -1) {
|
|
||||||
res.send("User does not exist")
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (users.users[get_userID(username)]['hash'] == password) { // Password matches
|
|
||||||
posts.posts.push({
|
|
||||||
"userID": get_userID(username),
|
|
||||||
"title": title,
|
|
||||||
"content": content,
|
|
||||||
"pubdate": unix_timestamp,
|
|
||||||
"editdate": unix_timestamp,
|
|
||||||
"tags": tags,
|
|
||||||
})
|
|
||||||
fs.writeFileSync(`${__dirname}/posts.js`, `export const posts = ${JSON.stringify(posts.posts)}`, 'utf-8');
|
|
||||||
comments.comments.push([])
|
|
||||||
fs.writeFileSync(`${__dirname}/comments.js`, `export const comments = ${JSON.stringify(comments.comments)}\nexport const counter = ${comments.counter}`)
|
|
||||||
res.redirect(302, "/");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.send(`Invalid Password for user`,username);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.listen(config.port, () => {
|
|
||||||
console.log(`Server is running at http://localhost:${config.port} in ${config.root_path}`);
|
|
||||||
});
|
|
4
docs/CLASSES_AND_IDS.md
Normal file
4
docs/CLASSES_AND_IDS.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
Post:
|
||||||
|
|
||||||
|

|
||||||
|
|
47
docs/CONFIG.md
Executable file
47
docs/CONFIG.md
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
# Configuration Documentation
|
||||||
|
## Introduction
|
||||||
|
The configuration file is stored in a file called config.json, for an example, copy example-config.json to config.json (`cp example-config.json config.json`) and modify from there.<br/>
|
||||||
|
Currently all values in example-config.json are required, however I plan to add support for default values in the case of no value being set.<br/>
|
||||||
|
All options show an example configuartion value and the variable type + an explaination below it.<br/>
|
||||||
|
|
||||||
|
## Technical configuration
|
||||||
|
| name | example value | variable type | explanation |
|
||||||
|
|-----------------|----------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| site_url | "https://example.com" | String | This value defines the url of your site, this used for the RSS feed to link back to post. |
|
||||||
|
| port | 8080 | Integer | This value defines the port that you run the blog on. Don't change this value if you don't know what that means. |
|
||||||
|
| allow_signup | true | Boolean | Defines weather new people should be allowed to signup. |
|
||||||
|
| timeline_length | 20 | Integer | How many posts will be shown on the timeline (home page). |
|
||||||
|
| enable_hitcount | true | Boolean | Enabling the hitcount (a number that represents the amount of front page loads (stored in hitcount.txt)) can slightly slow down loading of the front page. |
|
||||||
|
| charset | "UTF-8" | String | This is the value in the <meta charset=""> tag in the html of all pages, you should not change this unless you know why. |
|
||||||
|
| root_path | "/path/to/root/of/website" | String | Anything in this directory will be in the webroot, so put favicon.ico and anything else here. |
|
||||||
|
|
||||||
|
## Basic Customisation
|
||||||
|
| name | example value | variable type | explanation |
|
||||||
|
|-----------------|----------------------------|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
|
|locale|"en"|String|Your locale, see [/locales](/locales) for a list of all locales (you can open a PR for a new translation too)|
|
||||||
|
|seperator|"\<hr/\>"|String|This is what %S represents in the formatting, this will go inbetween posts and generally to seperate out content on pages.|
|
||||||
|
|site_name|"My Blog"|String|This is what %Y represents; it's the name of your instance, a human readable string.|
|
||||||
|
|site_description|"Read my blogs!"|String|This is what %W represents; it's the description of your instance, a human readable string.|
|
||||||
|
|default_commenter_username|"Anon"|String|Default commenter username if no username is inputted in comment submission.|
|
||||||
|
|
||||||
|
## Syndication
|
||||||
|
| name | example value | variable type | explanation |
|
||||||
|
|------|---------------|---------------|-------------------------------|
|
||||||
|
| rss | true | Boolean | Enable or Disable RSS feeds. |
|
||||||
|
| atom | true | Boolean | Enable or Disable ATOM feeds. |
|
||||||
|
|
||||||
|
## Dates
|
||||||
|
Read more at [date-fns](https://date-fns.org/v4.1.0/docs/format)<br/>
|
||||||
|
| name | example value | variable type | explanation |
|
||||||
|
|------|---------------|---------------|-------------------------------|
|
||||||
|
|date_format|"yyyy-MM-dd"|String|The format of date's on the website.|
|
||||||
|
|time_zone|"+0000"|String|\Your offset from UTC|
|
||||||
|
|
||||||
|
## Advanced Customisation
|
||||||
|
* /views/* files are EJS files (used for formatting HTML) and can be editted to your liking, you might want to read [the EJS docs](https://ejs.co/#docs) for help.
|
||||||
|
* "css": "body { background: red; }"<br/>
|
||||||
|
String. Custom CSS to be applied to all pages, if you want more complex css, you can edit custom.css.<br/>
|
||||||
|
You can also edit the custom.css file in the webroot, as by default this is linked in the global header.
|
||||||
|
|
||||||
|
## Custom Strings
|
||||||
|
* You can edit all the strings on the site in /locales/<your-locale>.json
|
1
docs/CONTRIBUTING.md
Normal file
1
docs/CONTRIBUTING.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Just open a PR or something, if it's good I'll pull
|
4
docs/DOCUMENTATION.md
Normal file
4
docs/DOCUMENTATION.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
All documentation is under construction as the program is also under construction and so is constantly changing and is also a mess and I'm shit at documentation
|
||||||
|
- [EJS Variables and functions](EJS.md)
|
||||||
|
- [configuring config.json](CONFIG.md)
|
||||||
|
- [Contributing](CONTRIBUTING.md)
|
27
docs/EJS.md
Normal file
27
docs/EJS.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
This is not a guide on how EJS works, look at [EJS's website](https://ejs.co/) for that!<br/>
|
||||||
|
This is just a list of functions and pieces of information provided to each EJS file.<br/>
|
||||||
|
<br/>
|
||||||
|
# syndication/global_rss:
|
||||||
|
- All config.json data
|
||||||
|
- All posts from posts.json
|
||||||
|
- showdown.JS's converter functions
|
||||||
|
- All functions in functions.js
|
||||||
|
# syndication/user_rss:
|
||||||
|
- All config.json data
|
||||||
|
- All posts from posts.json
|
||||||
|
- showdown.JS's converter functions
|
||||||
|
- All functions in functions.js
|
||||||
|
- the userID of the user in question (integer)
|
||||||
|
# syndication/global_atom:
|
||||||
|
- All config.json data
|
||||||
|
- All posts from posts.json
|
||||||
|
- showdown.JS's converter functions
|
||||||
|
- All functions in functions.js
|
||||||
|
- getUnixTime function from date-fns
|
||||||
|
# syndication/user_atom:
|
||||||
|
- All config.json data
|
||||||
|
- All posts from posts.json
|
||||||
|
- showdown.JS's converter functions
|
||||||
|
- All functions in functions.js
|
||||||
|
- the userID of the user in question (integer)
|
||||||
|
- getUnixTime function from date-fns
|
12
docs/INSTALLATION.md
Normal file
12
docs/INSTALLATION.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Installation
|
||||||
|
This program is currently just ran manually.<br/>
|
||||||
|
All you need to do is clone the git repository:<br/>
|
||||||
|
```git clone https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs.git```<br/>
|
||||||
|
Then navigate to /src:<br/>
|
||||||
|
```cd src```<br/>
|
||||||
|
Then run the initialisation function:<br/>
|
||||||
|
```node server.js --first-time```<br/>
|
||||||
|
Then you should modify config.json in / to suit your needs.<br/>
|
||||||
|
# Running
|
||||||
|
I would reccomend running the program in tmux so it does not stop running when you close the terminal window.<br/>
|
||||||
|
• There is currently no init system support. I might add this later (or you could open a PR).
|
BIN
docs/images/post-css.png
Normal file
BIN
docs/images/post-css.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 239 KiB |
@@ -1,105 +0,0 @@
|
|||||||
export const seperator = "<hr/>"
|
|
||||||
export const site_name = "My Blog"
|
|
||||||
export const site_url = "https://example.com"
|
|
||||||
export const port = 8080
|
|
||||||
export const site_description = "Read my blogs!"
|
|
||||||
export const timeline_length = 20
|
|
||||||
export const enable_hitcount = true // Can slow down page loading a bit
|
|
||||||
export const charset = "UTF-8" // Don't change unless you know why
|
|
||||||
|
|
||||||
// Anything in this directory will be in the webroot, so put favicon.ico and anything else here.
|
|
||||||
export const root_path = "/path/to/root/of/website"
|
|
||||||
|
|
||||||
// Default username if no username is inputted in comment submission
|
|
||||||
export const default_username = "Anon"
|
|
||||||
|
|
||||||
// RSS feeds
|
|
||||||
export const rss = true
|
|
||||||
export const rss_path = "/rss"
|
|
||||||
|
|
||||||
// Dates
|
|
||||||
// https://date-fns.org/v4.1.0/docs/format
|
|
||||||
export const date_format = "yyyy-MM-dd"
|
|
||||||
export const time_zone = "+0000"
|
|
||||||
|
|
||||||
//// Format /////
|
|
||||||
// The syntax for this is pretty simple
|
|
||||||
// %% - A literal %
|
|
||||||
// %A - List of tags
|
|
||||||
// %B - List of tags, each one with a hyperlink to that tag page
|
|
||||||
// %C - Post content
|
|
||||||
// %D - Published date in the format specified by date_format
|
|
||||||
// %E - Edited date in the format specified by date_format
|
|
||||||
// %F - Pretty name
|
|
||||||
// %G - Tag name (used for the tag page only)
|
|
||||||
// %H - Frontpage hit count
|
|
||||||
// %I - User description
|
|
||||||
// %L - URL Permanent link to the post
|
|
||||||
// %M - comments
|
|
||||||
// %N - the username of the user (poster)
|
|
||||||
// %P - URL to create a new post
|
|
||||||
// %O - URL to edit this post
|
|
||||||
// %R - Site wide RSS feed
|
|
||||||
// %S - post seperator as defined by post_seperator
|
|
||||||
// %T - Title
|
|
||||||
// %U - URL the the user (poster)
|
|
||||||
// %W - Site Description as defined by site_description
|
|
||||||
// %X - Comment submission box
|
|
||||||
// %Y - Site Name as defined by site_name
|
|
||||||
// %Z - Attribution (to me) and source code link and license
|
|
||||||
|
|
||||||
export const timeline_header = `<h1>%Y</h1>
|
|
||||||
<h2>%W</h2>
|
|
||||||
<a href="%P">Create Post</a><br/>
|
|
||||||
<a href="%R">RSS Feed</a><br/>
|
|
||||||
Hit count: %H
|
|
||||||
%S`
|
|
||||||
export const user_page_header = `<h1>%F's posts:</h1>
|
|
||||||
%I
|
|
||||||
%S`
|
|
||||||
export const tag_page_header = `<h1>Posts tagged: %G</h1>%S`
|
|
||||||
// ---------------------------------------------
|
|
||||||
export const user_post_format = `<h2>%T</h2>
|
|
||||||
<p>%C</p>
|
|
||||||
<i>%B</i><br/>
|
|
||||||
<a href="%L">Permalink</a><br/>
|
|
||||||
%X
|
|
||||||
%M
|
|
||||||
%S`
|
|
||||||
export const post_page_format = `<h1>%T</h1>
|
|
||||||
<p>%C</p>
|
|
||||||
<i>%B</i><br/>
|
|
||||||
<i>By <a href="%U">%N</a></i><br/>
|
|
||||||
<a href="%O">Edit Post</a><br/>
|
|
||||||
<i>Posted: %D</i><br/>
|
|
||||||
<i>Edited: %E</i>
|
|
||||||
%S
|
|
||||||
%X
|
|
||||||
%M
|
|
||||||
%S`
|
|
||||||
export const timeline_post_format = `<h3>%T</h3>
|
|
||||||
<p>%C</p>
|
|
||||||
<a href="%L">Permalink</a><br/>
|
|
||||||
<i>By <a href="%U">%N</a></i>
|
|
||||||
%X
|
|
||||||
%M
|
|
||||||
%S`
|
|
||||||
export const tag_post_format = `<h3>%T</h3>
|
|
||||||
<p>%C</p>
|
|
||||||
<i>%B</i><br/>
|
|
||||||
<a href="%L">Permalink</a><br/>
|
|
||||||
<i>By <a href="%U">%N</a></i>
|
|
||||||
%S`
|
|
||||||
// -------------------------------------
|
|
||||||
export const site_wide_footer = `Site is ran by DeaDvey<br/>
|
|
||||||
%Z`
|
|
||||||
|
|
||||||
|
|
||||||
/// Custom CSS to be applied to every page
|
|
||||||
export const css = `
|
|
||||||
/* Put you custom CSS here,
|
|
||||||
Read about existing classes and ID's in the docs (coming soon)*\
|
|
||||||
`
|
|
||||||
|
|
||||||
// pretty please don't change this
|
|
||||||
export const attribution = "Powered by blogger-nodejs: <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs'>Source Code</a>, <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs/raw/branch/master/LICENSE'>license (WTFPL)</a>"
|
|
36
example-config.json
Executable file
36
example-config.json
Executable file
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"site_admin": "your name",
|
||||||
|
"seperator": "<hr/>",
|
||||||
|
"site_name": "My Blog",
|
||||||
|
"site_url": "https://example.com",
|
||||||
|
"language": "en-US",
|
||||||
|
"port": 8080,
|
||||||
|
"allow_signup": true,
|
||||||
|
"site_description": "Read my blogs!",
|
||||||
|
"timeline_length": 20,
|
||||||
|
"enable_hitcount": true,
|
||||||
|
"charset": "UTF-8",
|
||||||
|
"root_path": "/path/to/webroot",
|
||||||
|
"edit_account_base_url": "/edit_account",
|
||||||
|
"new_post_url": "/post",
|
||||||
|
"signup_url": "/signup",
|
||||||
|
"edit_post_base_url": "/edit",
|
||||||
|
"default_comenter_username": "Anon",
|
||||||
|
"rss": true,
|
||||||
|
"atom": true,
|
||||||
|
"date_format": "yyyy-MM-dd",
|
||||||
|
"time_zone": "+0000",
|
||||||
|
"string": {
|
||||||
|
"signup_agreement": "I agree to not post illegal or hateful content",
|
||||||
|
"signups_unavailable": "Sorry, this server does not allow signups",
|
||||||
|
"user_exists": "Sorry, this user already exists, try a different username",
|
||||||
|
"user_doesnt_exist": "Sorry, this user does not exist",
|
||||||
|
"comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
|
||||||
|
"post_doesnt_exist": "This post doesn't exist or was deleted",
|
||||||
|
"delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)",
|
||||||
|
"incorrect_password": "Incorrect Password",
|
||||||
|
"rss_disabled": "Sorry, RSS is disabled",
|
||||||
|
"attribution": "Powered by blogger-nodejs: <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs'>Source Code</a>, <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs/raw/branch/master/LICENSE'>license (WTFPL)</a>"
|
||||||
|
},
|
||||||
|
"css": ""
|
||||||
|
}
|
@@ -1 +0,0 @@
|
|||||||
244
|
|
42
locales/en-GB.json
Normal file
42
locales/en-GB.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"quotes": "“”‘’",
|
||||||
|
"password": "Password",
|
||||||
|
"username": "Username",
|
||||||
|
"prettyname": "Prettyname",
|
||||||
|
"description": "Description (social links, what you write about etc), supports markdown",
|
||||||
|
"title": "Title",
|
||||||
|
"post_content": "Post Content, supports markdown",
|
||||||
|
"tags": "Tags (comma seperated)",
|
||||||
|
"delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)",
|
||||||
|
"signup_agreement": "I agree to not post illegal or hateful content",
|
||||||
|
"comment": "Comment",
|
||||||
|
"submit": "Sumbit",
|
||||||
|
|
||||||
|
"site_ran_by": "Site is ran by",
|
||||||
|
"signups_unavailable": "Sorry, this server does not allow signups",
|
||||||
|
"user_exists": "Sorry, this user already exists, try a different username",
|
||||||
|
"user_doesnt_exist": "Sorry, this user does not exist",
|
||||||
|
"comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
|
||||||
|
"post_doesnt_exist": "This post doesn't exist or was deleted",
|
||||||
|
"incorrect_password": "Incorrect Password",
|
||||||
|
"rss_disabled": "Sorry, RSS is disabled",
|
||||||
|
"atom_disabled": "Sorry, ATOM is disabled",
|
||||||
|
"AI_consent": "The content on this website may not be copied, scraped, or used to train AI models or large language models (LLMs) without prior written consent.",
|
||||||
|
|
||||||
|
"rss_feed": "RSS Feed",
|
||||||
|
"atom_feed": "ATOM Feed",
|
||||||
|
"no_tags": "No Tags",
|
||||||
|
"new_post": "New Post",
|
||||||
|
"edit_post": "Edit Post",
|
||||||
|
"sign_up": "Sign Up",
|
||||||
|
"edit_account": "Edit Account",
|
||||||
|
"permalink": "Permalink",
|
||||||
|
"written_by": "Written by",
|
||||||
|
"published": "Published",
|
||||||
|
"last_modified": "Last Modified",
|
||||||
|
"hitcount": "Hitcount",
|
||||||
|
"posts_tagged": "Posts Tagged",
|
||||||
|
"home_page": "Home Page",
|
||||||
|
"site_index": "Site Index",
|
||||||
|
"attribution": "Powered by blogger-nodejs: <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs'>Source Code</a>, <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs/raw/branch/master/LICENSE'>license (WTFPL)</a>"
|
||||||
|
}
|
42
locales/en-US.json
Normal file
42
locales/en-US.json
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"quotes": "“”‘’",
|
||||||
|
"password": "Password",
|
||||||
|
"username": "Username",
|
||||||
|
"prettyname": "Prettyname",
|
||||||
|
"description": "Description (social links, what you write about etc), supports markdown",
|
||||||
|
"title": "Title",
|
||||||
|
"post_content": "Post Content, supports markdown",
|
||||||
|
"tags": "Tags (comma seperated)",
|
||||||
|
"delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)",
|
||||||
|
"signup_agreement": "I agree to not post illegal or hateful content",
|
||||||
|
"comment": "Comment",
|
||||||
|
"submit": "Sumbit",
|
||||||
|
|
||||||
|
"site_ran_by": "Site is ran by",
|
||||||
|
"signups_unavailable": "Sorry, this server does not allow signups",
|
||||||
|
"user_exists": "Sorry, this user already exists, try a different username",
|
||||||
|
"user_doesnt_exist": "Sorry, this user does not exist",
|
||||||
|
"comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
|
||||||
|
"post_doesnt_exist": "This post doesn't exist or was deleted",
|
||||||
|
"incorrect_password": "Incorrect Password",
|
||||||
|
"rss_disabled": "Sorry, RSS is disabled",
|
||||||
|
"atom_disabled": "Sorry, ATOM is disabled",
|
||||||
|
"AI_consent": "The·content·on·this·website·may·not·be·copied,·scraped,·or·used·to·train·AI·models·or·large·language·models·(LLMs)·without·prior·written·consent.",
|
||||||
|
|
||||||
|
"rss_feed": "RSS Feed",
|
||||||
|
"atom_feed": "ATOM Feed",
|
||||||
|
"no_tags": "No Tags",
|
||||||
|
"new_post": "New Post",
|
||||||
|
"edit_post": "Edit Post",
|
||||||
|
"sign_up": "Sign Up",
|
||||||
|
"edit_account": "Edit Account",
|
||||||
|
"permalink": "Permalink",
|
||||||
|
"written_by": "Written by",
|
||||||
|
"published": "Published",
|
||||||
|
"last_modified": "Last Modified",
|
||||||
|
"hitcount": "Hitcount",
|
||||||
|
"posts_tagged": "Posts Tagged",
|
||||||
|
"home_page": "Home Page",
|
||||||
|
"site_index": "Site Index",
|
||||||
|
"attribution": "Powered by blogger-nodejs: <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs'>Source Code</a>, <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs/raw/branch/master/LICENSE'>license (WTFPL)</a>"
|
||||||
|
}
|
39
locales/template.json
Normal file
39
locales/template.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"quotes": "“”‘’",
|
||||||
|
"password": "Password",
|
||||||
|
"username": "Username",
|
||||||
|
"prettyname": "Prettyname",
|
||||||
|
"description": "Description (social links, what you write about etc), supports markdown",
|
||||||
|
"title": "Title",
|
||||||
|
"post_content": "Post Content, supports markdown",
|
||||||
|
"tags": "Tags (comma seperated)",
|
||||||
|
"delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)",
|
||||||
|
"signup_agreement": "I agree to not post illegal or hateful content",
|
||||||
|
"comment": "Comment",
|
||||||
|
"submit": "Sumbit",
|
||||||
|
|
||||||
|
"signups_unavailable": "Sorry, this server does not allow signups",
|
||||||
|
"user_exists": "Sorry, this user already exists, try a different username",
|
||||||
|
"user_doesnt_exist": "Sorry, this user does not exist",
|
||||||
|
"comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
|
||||||
|
"post_doesnt_exist": "This post doesn't exist or was deleted",
|
||||||
|
"incorrect_password": "Incorrect Password",
|
||||||
|
"rss_disabled": "Sorry, RSS is disabled",
|
||||||
|
"atom_disabled": "Sorry, ATOM is disabled",
|
||||||
|
|
||||||
|
"rss_feed": "RSS Feed",
|
||||||
|
"atom_feed": "ATOM Feed",
|
||||||
|
"new_post": "New Post",
|
||||||
|
"edit_post": "Edit Post",
|
||||||
|
"sign_up": "Sign Up",
|
||||||
|
"edit_account": "Edit Account",
|
||||||
|
"permalink": "Permalink",
|
||||||
|
"written_by": "Written by",
|
||||||
|
"published": "Published",
|
||||||
|
"last_modified": "Last Modified",
|
||||||
|
"hitcount": "Hitcount",
|
||||||
|
"posts_tagged": "Posts Tagged",
|
||||||
|
"home_page": "Home Page",
|
||||||
|
"site_index": "Site Index",
|
||||||
|
"attribution": "Powered by blogger-nodejs: <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs'>Source Code</a>, <a href='https://git.javalsai.tuxcord.net/deadvey/blogger-nodejs/raw/branch/master/LICENSE'>license (WTFPL)</a>"
|
||||||
|
}
|
@@ -1,8 +1,13 @@
|
|||||||
{
|
{
|
||||||
|
"name": "blogger-nodejs",
|
||||||
|
"version": "0.0.5",
|
||||||
|
"description": "Simple web logging backend",
|
||||||
|
"author": "DeaDvey",
|
||||||
|
"license": "WTFPL",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto": "^1.0.1",
|
|
||||||
"date-fns": "^4.1.0",
|
"date-fns": "^4.1.0",
|
||||||
|
"ejs": "^3.1.10",
|
||||||
"express": "^5.1.0",
|
"express": "^5.1.0",
|
||||||
"showdown": "^2.1.0"
|
"markdown-it": "^14.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
118
src/functions.js
Normal file
118
src/functions.js
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import { createRequire } from 'module';
|
||||||
|
const require = createRequire(import.meta.url)
|
||||||
|
const config = require("../config.json")
|
||||||
|
const locale = require(`../locales/${config.locale}.json`)
|
||||||
|
|
||||||
|
// The configuration defines a date format using the date-fns (a datetime library) syntax
|
||||||
|
// eg "yyyy-MM-dd"
|
||||||
|
// this converts unix time (an integer) into a string that is formatted according to config.js
|
||||||
|
// uses date-fns's fromUnixTime() and format() functions
|
||||||
|
// returns the formatted date (string)
|
||||||
|
export function unix_time_to_date_format(unix_time) {
|
||||||
|
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
|
||||||
|
let date = fromUnixTime(unix_time)
|
||||||
|
let formatted_date = format(date, config.date_format)
|
||||||
|
return formatted_date
|
||||||
|
}
|
||||||
|
// This is similar to the above function, however, instead of formatting to the users
|
||||||
|
// configuration, it formats to RFC-822 which is the date format used by RSS feeds
|
||||||
|
// eg "Mon, 23 May 2025 18:59:59 +0100"
|
||||||
|
// accepts unix time (int)
|
||||||
|
// returns the formatted date (string)
|
||||||
|
export function unix_time_to_rss_date(unix_time) {
|
||||||
|
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
|
||||||
|
let date = fromUnixTime(unix_time)
|
||||||
|
let formatted_date = format(date, "EEE, dd MMM yyyy HH:mm:ss")
|
||||||
|
return `${formatted_date} ${config.time_zone}`
|
||||||
|
}
|
||||||
|
// And again with atom's date format
|
||||||
|
export function unix_time_to_atom_date(unix_time) {
|
||||||
|
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
|
||||||
|
let date = fromUnixTime(unix_time)
|
||||||
|
let formatted_date = format(date, "yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||||
|
return `${formatted_date}`
|
||||||
|
}
|
||||||
|
// This function accepts a list of strings eg ["string1","string2,"string3"] (any length)
|
||||||
|
// then returns a string of them each pointing to a seperate url
|
||||||
|
// eg "<a href="/tag/string1">string1</a>, <a href="/tag/string2">string2</a>, <a href="/tag/string3">string3</a>"
|
||||||
|
// this is so you can have a list of tags that each point to their individual tag page
|
||||||
|
// returns: string
|
||||||
|
export function render_tags(tags) {
|
||||||
|
let string = "" // Initialises the string
|
||||||
|
if (tags.length == 1 && tags[0] == "") {
|
||||||
|
string = locale.no_tags; // If there are no tags, output something
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag
|
||||||
|
string += `<a href="/tag/${tags[tag_index]}">${tags[tag_index]}</a>` // Adds the tag to the string as a HTML href
|
||||||
|
if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma
|
||||||
|
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("../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
|
||||||
|
}
|
||||||
|
|
||||||
|
export function get_comment(commentID) { // TODO scales like shit
|
||||||
|
const comments = require("../data/comments.json")
|
||||||
|
for (let i = 0; i < comments.comments.length; i++) { // Loop over every post
|
||||||
|
for (let j = 0; j < comments.comments[i].length; j++) { // Then every comment in that post
|
||||||
|
if (comments.comments[i][j]["id"] == commentID) {
|
||||||
|
return comments.comments[i][j]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1 // If comment is not present, return -1
|
||||||
|
}
|
||||||
|
// This escapes some potentially dangerous HTML characters with their HTML entities
|
||||||
|
// https://www.freeformatter.com/html-entities.html
|
||||||
|
// accepts a string
|
||||||
|
// returns a string with some character replaced by their entities
|
||||||
|
export function escape_input(input) {
|
||||||
|
let output = input
|
||||||
|
.replaceAll("<", "<")
|
||||||
|
.replaceAll(">", ">")
|
||||||
|
.replaceAll("\\", "\")
|
||||||
|
.replaceAll('"', """)
|
||||||
|
.replaceAll("'", "'")
|
||||||
|
.replaceAll("/", "/")
|
||||||
|
.replaceAll("%", "%")
|
||||||
|
.replaceAll("&", "&")
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render comment content by replacing the >> int with a url link to that comment
|
||||||
|
export function render_comment(comment_content) {
|
||||||
|
return comment_content
|
||||||
|
.replaceAll(/>> ([0-9]*)/g, "<a href='/comment/$1'>>> $1</a>")
|
||||||
|
.replaceAll(/>>([0-9]*)/g, "<a href='/comment/$1'>>>$1</a>")
|
||||||
|
.replaceAll(/>> ([0-9]*)/g, "<a href='/comment/$1'>>> $1</a>")
|
||||||
|
.replaceAll(/>>([0-9]*)/g, "<a href='/comment/$1'>>>$1</a>")
|
||||||
|
.replaceAll("\n", "<br/>")
|
||||||
|
};
|
||||||
|
export function render_md(content) {
|
||||||
|
const markdownit = require("markdown-it")
|
||||||
|
const md = markdownit({
|
||||||
|
html: false,
|
||||||
|
xhtmlOut: false,
|
||||||
|
breaks: true,
|
||||||
|
linkify: false,
|
||||||
|
typographer: true,
|
||||||
|
quotes: locale.quotes,
|
||||||
|
})
|
||||||
|
return md.render(content)
|
||||||
|
};
|
51
src/initialise.js
Normal file
51
src/initialise.js
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { createRequire } from 'module';
|
||||||
|
const require = createRequire(import.meta.url)
|
||||||
|
// Initialise the program by creating users.js, comments.js, posts.js and config.js
|
||||||
|
// All require default content in them to start off with
|
||||||
|
// Then exit successfully
|
||||||
|
// returns nothing
|
||||||
|
export function initialise() {
|
||||||
|
const fs = require("fs");
|
||||||
|
try {
|
||||||
|
const users = require("../data/users.json");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Creating users file")
|
||||||
|
fs.writeFileSync(`../data/users.json`, `[]`)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const posts = require("../data/posts.json");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Creating posts file")
|
||||||
|
fs.writeFileSync(`../data/posts.json`, `[]`)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const comments = require("../data/comments.json");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Creating comments file")
|
||||||
|
fs.writeFileSync(`../data/comments.json`, `{\n"comments": [],\n"counter": 0}`)
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const config = require("../config.json");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Copying the example config to config.js")
|
||||||
|
console.log("!!! PLEASE MODIFY config.json TO YOUR NEEDS !!!")
|
||||||
|
fs.copyFile('../example-config.json', '../config.json', (err) => {
|
||||||
|
console.log("Error copying file")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
fs.readFileSync("../data/hitcount.txt")
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("Creating hitcount file")
|
||||||
|
fs.writeFileSync("../data/hitcount.txt", "0", (err) => {
|
||||||
|
console.log("Error creating hitcount.txt")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
console.log("Successfully initialised")
|
||||||
|
process.exit(0)
|
||||||
|
}
|
520
src/server.js
Normal file
520
src/server.js
Normal file
@@ -0,0 +1,520 @@
|
|||||||
|
// Get the libraries
|
||||||
|
const fs = require('fs'); // For modifying and reading files
|
||||||
|
const express = require('express'); // For running a webserver in nodejs
|
||||||
|
const crypto = require('crypto'); // For encrypting passwords, I use sha512
|
||||||
|
// fromUnixTime(): Create a date from a Unix timestamp (in seconds). Decimal values will be discarded.
|
||||||
|
// format(): Return the formatted date string in the given format. The result may vary by locale.
|
||||||
|
// getUnixTime(): Get the seconds timestamp of the given date.
|
||||||
|
// find out more at https://date-fns.org/ \or docs: https://date-fns.org/docs/Getting-Started
|
||||||
|
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
|
||||||
|
const ejs = require("ejs")
|
||||||
|
const func = require("./functions.js")
|
||||||
|
const init = require("./initialise.js")
|
||||||
|
|
||||||
|
// There's only one possible argument, so we can just check if the user passed that one
|
||||||
|
// TODO I plan on adding more such as --help and --post so I should make this more robust at some point
|
||||||
|
if (process.argv[2] == "--first-time") {
|
||||||
|
init.initialise() // Creates any files such users.js, posts.js, comments.js or config.js if they are not present
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define the modules now so they are global
|
||||||
|
let users // contains a list of users, each user is an object containing username,prettyname,hash and description
|
||||||
|
let posts // contains a list of posts,
|
||||||
|
let comments // contains a list of comments
|
||||||
|
let config // contains a set of configuration for the site, see example-config.js for an example
|
||||||
|
|
||||||
|
try {
|
||||||
|
// We're going to try and import the modules,
|
||||||
|
users = require('../data/users.json');
|
||||||
|
posts = require('../data/posts.json');
|
||||||
|
comments = require('../data/comments.json');
|
||||||
|
config = require('../config.json');
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// if they don't all import then
|
||||||
|
// inform the user to pass --first-time and exit with an error code
|
||||||
|
console.log("A file is missing!")
|
||||||
|
console.log("Run with --first-time to initialise the program")
|
||||||
|
console.log(error)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import the locale
|
||||||
|
try {
|
||||||
|
locale = require(`../locales/${config.locale}.json`);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log("This locale doesn't exist, if you want to create it then you can create a PR")
|
||||||
|
console.log("Locale selected: ", config.locale)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define stuff to do with express (nodejs webserver)
|
||||||
|
const app = express();
|
||||||
|
app.use(express.urlencoded({ extended: true }));
|
||||||
|
app.use(express.json());
|
||||||
|
app.use(express.static(config.root_path));
|
||||||
|
// set the view engine to ejs
|
||||||
|
app.set('view engine', 'ejs');
|
||||||
|
app.set('views', '../views')
|
||||||
|
|
||||||
|
////////////////////// SYNDICATION ////////////////////////
|
||||||
|
// global RSS protocol gets
|
||||||
|
app.get("/rss", (req,res) => {
|
||||||
|
if (config.rss == false) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.rss_disabled,
|
||||||
|
config: config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.setHeader('content-type', 'application/rss+xml');
|
||||||
|
res.render("syndication/global_rss", {
|
||||||
|
config,
|
||||||
|
posts,
|
||||||
|
func,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// user RSS protocol gets
|
||||||
|
app.get("/user/:username/rss", (req,res) => {
|
||||||
|
const username = req.params.username;
|
||||||
|
const userID = func.get_userID(username);
|
||||||
|
if (config.rss == false) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.rss_disabled,
|
||||||
|
config: config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.setHeader('content-type', 'application/rss+xml');
|
||||||
|
res.render("syndication/user_rss", {
|
||||||
|
config,
|
||||||
|
posts,
|
||||||
|
func,
|
||||||
|
userID,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// global ATOM protocol gets
|
||||||
|
app.get("/atom", (req,res) => {
|
||||||
|
if (config.atom == false) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.atom_disabled,
|
||||||
|
config: config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.setHeader('content-type', 'application/rss+xml');
|
||||||
|
res.render("syndication/global_atom", {
|
||||||
|
config,
|
||||||
|
posts,
|
||||||
|
func,
|
||||||
|
getUnixTime,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// user ATOM protocol gets
|
||||||
|
app.get("/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,
|
||||||
|
config: config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.setHeader('content-type', 'application/rss+xml');
|
||||||
|
res.render("syndication/user_atom", {
|
||||||
|
config,
|
||||||
|
posts,
|
||||||
|
func,
|
||||||
|
userID,
|
||||||
|
getUnixTime,
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
///////////////////// Page index's ///////////////////////
|
||||||
|
app.get("/index/pages", (req,res) => {
|
||||||
|
res.render("indexes/all_pages", {
|
||||||
|
config,
|
||||||
|
posts,
|
||||||
|
users,
|
||||||
|
comments: comments.comments,
|
||||||
|
});
|
||||||
|
}); // /index/posts
|
||||||
|
app.get("/index/posts", (req,res) => {
|
||||||
|
res.render("indexes/posts", {
|
||||||
|
config,
|
||||||
|
posts,
|
||||||
|
});
|
||||||
|
}); // /index/posts
|
||||||
|
app.get("/index/users", (req,res) => {
|
||||||
|
res.render("indexes/users", {
|
||||||
|
config,
|
||||||
|
users,
|
||||||
|
});
|
||||||
|
}); // /index/posts
|
||||||
|
app.get("/index/comments", (req,res) => {
|
||||||
|
res.render("indexes/comments", {
|
||||||
|
config,
|
||||||
|
comments: comments.comments,
|
||||||
|
});
|
||||||
|
}); // /index/posts
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////// Standard Pages //////////////////////
|
||||||
|
app.get("/", (req,res) => {
|
||||||
|
// Increment the hitcount
|
||||||
|
if (config.enable_hitcount) {
|
||||||
|
let hitcount = parseInt(fs.readFileSync('../data/hitcount.txt'))
|
||||||
|
hitcount += 1
|
||||||
|
console.log(`/ Is loaded, hitcount: ${hitcount}`)
|
||||||
|
fs.writeFileSync(`../data/hitcount.txt`, `${hitcount}`, 'utf-8');
|
||||||
|
}
|
||||||
|
|
||||||
|
res.render("pages/timeline",
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
posts,
|
||||||
|
users,
|
||||||
|
comments: comments.comments,
|
||||||
|
hitcount: fs.readFileSync("../data/hitcount.txt"),
|
||||||
|
fromUnixTime,
|
||||||
|
format,
|
||||||
|
getUnixTime,
|
||||||
|
func,
|
||||||
|
})
|
||||||
|
}); // /
|
||||||
|
app.get("/user/:username", (req, res) => {
|
||||||
|
const userID = func.get_userID(req.params.username)
|
||||||
|
console.log(userID)
|
||||||
|
if (userID != -1) {
|
||||||
|
res.render("pages/user",
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
posts,
|
||||||
|
user: users[userID],
|
||||||
|
userID: userID,
|
||||||
|
comments: comments.comments,
|
||||||
|
fromUnixTime: fromUnixTime,
|
||||||
|
format: format,
|
||||||
|
getUnixTime: getUnixTime,
|
||||||
|
func,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (userID == -1) {
|
||||||
|
res.render("partials/message",
|
||||||
|
{
|
||||||
|
message: locale.user_doesnt_exist,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}); // /user/:username
|
||||||
|
app.get("/post/:post_index", (req, res) => {
|
||||||
|
const postID = req.params.post_index
|
||||||
|
if (postID > posts.length-1 || posts[postID]["deleted"] == true) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.post_doesnt_exist,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else if (typeof posts[postID]["deleted"] == "undefined" || posts[postID]["deleted"] == false) {
|
||||||
|
res.render("pages/post",
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
post: posts[postID],
|
||||||
|
postID: postID,
|
||||||
|
user: users[posts[postID].userID],
|
||||||
|
comments: comments.comments[postID],
|
||||||
|
fromUnixTime,
|
||||||
|
format,
|
||||||
|
getUnixTime,
|
||||||
|
func,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("Error loading page")
|
||||||
|
res.redirect(301,"/")
|
||||||
|
}
|
||||||
|
}); // /post/:post_index
|
||||||
|
app.get("/tag/:tag", (req,res) => {
|
||||||
|
const tag = req.params.tag
|
||||||
|
res.render("pages/tag",
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
tag,
|
||||||
|
posts,
|
||||||
|
users,
|
||||||
|
comments: comments.comments,
|
||||||
|
fromUnixTime: fromUnixTime,
|
||||||
|
format: format,
|
||||||
|
getUnixTime: getUnixTime,
|
||||||
|
func,
|
||||||
|
})
|
||||||
|
}); // /tag/:tag
|
||||||
|
app.get("/comment/:commentID", (req,res) => {
|
||||||
|
const commentID = req.params.commentID;
|
||||||
|
const comment = func.get_comment(commentID)
|
||||||
|
if (comment == -1) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
config,
|
||||||
|
message: locale.comment_doesnt_exist,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.render("pages/comment",
|
||||||
|
{
|
||||||
|
config: config,
|
||||||
|
locale,
|
||||||
|
post: posts[comment["id"]],
|
||||||
|
users,
|
||||||
|
comment,
|
||||||
|
fromUnixTime: fromUnixTime,
|
||||||
|
format: format,
|
||||||
|
getUnixTime: getUnixTime,
|
||||||
|
func,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////// Form pages ////////////////////////////
|
||||||
|
app.get(config.new_post_url, (req,res) => {
|
||||||
|
res.render("forms/new_post", {
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
});
|
||||||
|
}); // /post
|
||||||
|
app.get(config.signup_url, (req,res) => {
|
||||||
|
// if the server does allow signup
|
||||||
|
if (config.allow_signup == true) {
|
||||||
|
// Send the page for signing up to the server
|
||||||
|
res.render("forms/signup", {
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// if the server does not allow signup
|
||||||
|
else if (config.allow_signup == false) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.signups_unavailable,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// If allow_signup is undefined or not a boolean, error
|
||||||
|
else {
|
||||||
|
res.redirect(301,"/")
|
||||||
|
console.log("Error, invalid value for allow_signup (bool)")
|
||||||
|
}
|
||||||
|
}); // /signup
|
||||||
|
app.get(`${config.edit_account_base_url}/:user_id`, (req,res) => {
|
||||||
|
const userID = parseInt(req.params.user_id);
|
||||||
|
res.render("forms/edit_account", {
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
user: users[userID],
|
||||||
|
userID
|
||||||
|
});
|
||||||
|
}); // /delete_account
|
||||||
|
app.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
|
||||||
|
const post_id = req.params.post_id
|
||||||
|
const post = posts[post_id]
|
||||||
|
const user = users[post['userID']]
|
||||||
|
res.render("forms/edit_post", {
|
||||||
|
config,
|
||||||
|
locale,
|
||||||
|
post,
|
||||||
|
post_id,
|
||||||
|
user,
|
||||||
|
});
|
||||||
|
}); // /edit/:post_id
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////// Form actions /////////////////////////
|
||||||
|
app.post("/submit_comment", (req,res) => {
|
||||||
|
const unix_timestamp = getUnixTime(new Date())
|
||||||
|
let name = func.escape_input(req.body.name)
|
||||||
|
if (name == "") {
|
||||||
|
name = config.default_commenter_username
|
||||||
|
}
|
||||||
|
new_comment = {
|
||||||
|
"name": name,
|
||||||
|
"content": func.escape_input(req.body.content),
|
||||||
|
"id": comments.counter,
|
||||||
|
"pubdate": unix_timestamp
|
||||||
|
};
|
||||||
|
comments.counter += 1;
|
||||||
|
comments.comments[req.body.post_index].push(new_comment);
|
||||||
|
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
||||||
|
|
||||||
|
res.redirect(301,`/post/${req.body.post_index}`)
|
||||||
|
}); // /submit_comment
|
||||||
|
app.post("/submit_post", (req,res) => {
|
||||||
|
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
|
||||||
|
const username = func.escape_input(req.body.username)
|
||||||
|
const title = func.escape_input(req.body.title)
|
||||||
|
const content = req.body.content
|
||||||
|
const tags = func.escape_input(req.body.tags).split(',');
|
||||||
|
const unix_timestamp = getUnixTime(new Date())
|
||||||
|
|
||||||
|
if (func.get_userID(username) == -1) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.user_doesnt_exit,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (users[func.get_userID(username)]['hash'] == password) { // Password matches
|
||||||
|
console.log(username, "is submitting a post titled:", title);
|
||||||
|
posts.push({
|
||||||
|
"id": posts.length,
|
||||||
|
"userID": func.get_userID(username),
|
||||||
|
"title": title,
|
||||||
|
"content": content,
|
||||||
|
"pubdate": unix_timestamp,
|
||||||
|
"editdate": unix_timestamp,
|
||||||
|
"tags": tags,
|
||||||
|
})
|
||||||
|
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
||||||
|
comments.comments.push([])
|
||||||
|
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`)
|
||||||
|
res.redirect(302, "/");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.incorrect_password,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}); // /submit_post
|
||||||
|
app.post("/submit_signup", (req,res) => {
|
||||||
|
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
|
||||||
|
const username = func.escape_input(req.body.username)
|
||||||
|
const prettyname = func.escape_input(req.body.prettyname)
|
||||||
|
const description = req.body.description
|
||||||
|
|
||||||
|
// Check that signups are allowed
|
||||||
|
if (config.allow_signup == true) {
|
||||||
|
// func.get_userID will return -1 if the user does not exist
|
||||||
|
// so this checks that the user does not exist
|
||||||
|
if (func.get_userID(username) == -1) {
|
||||||
|
users.push({
|
||||||
|
"id": users.length,
|
||||||
|
"username": username,
|
||||||
|
"prettyname": prettyname,
|
||||||
|
"hash": password,
|
||||||
|
"description": description,
|
||||||
|
})
|
||||||
|
fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
|
||||||
|
res.redirect(301, `/user/${username}`)
|
||||||
|
}
|
||||||
|
// if the user does exist then
|
||||||
|
else {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.user_exists,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (config.allow_signup == false) {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.signups_unavailable,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// If allow_signup is undefined or not a boolean, error
|
||||||
|
else {
|
||||||
|
res.redirect(301,"/")
|
||||||
|
console.log("Error, invalid value for allow_signup (bool)")
|
||||||
|
}
|
||||||
|
}); // /submit_signup
|
||||||
|
app.post("/submit_edit_user", (req,res) => {
|
||||||
|
// Get the form info
|
||||||
|
const password = crypto.createHash("sha512").update(req.body.password).digest("hex");
|
||||||
|
const userID = func.escape_input(req.body.userID)
|
||||||
|
const description = req.body.description
|
||||||
|
const prettyname = func.escape_input(req.body.prettyname)
|
||||||
|
const delete_bool = req.body.delete
|
||||||
|
|
||||||
|
if (userID >= 0) { // The user exists
|
||||||
|
if (password == users[userID]['hash']) { // password matches
|
||||||
|
console.log(userID, " (userID) is modifying their account")
|
||||||
|
users[userID]["prettyname"] = prettyname;
|
||||||
|
users[userID]["description"] = description;
|
||||||
|
|
||||||
|
if (delete_bool == true) {
|
||||||
|
// Delete the user
|
||||||
|
users[userID] = {"id": userID,"deleted": true}
|
||||||
|
// Delete all their posts
|
||||||
|
for (let postid = 0; postid < posts.length; postid++) { // loop over all posts
|
||||||
|
if (posts[postid]['userID'] == userID) { // if userID matches
|
||||||
|
posts[postid] = {"id": postid, "deleted": true} // delete the post
|
||||||
|
comments.comments[postid] = [] // the comments for this post should also be deleted
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Write these changes
|
||||||
|
fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8');
|
||||||
|
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
||||||
|
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
||||||
|
res.redirect(301,`/user/${users[userID]["username"]}`)
|
||||||
|
}
|
||||||
|
else { // password does not match
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.incorrect_password,
|
||||||
|
config
|
||||||
|
}
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.user_doesnt_exist,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}); // /submit_delete_account
|
||||||
|
app.post("/submit_edit_post", (req,res) => {
|
||||||
|
const password = crypto.createHash('sha512').update(req.body.password).digest('hex');
|
||||||
|
const postID = req.body.postID
|
||||||
|
const userID = req.body.userID
|
||||||
|
const title = func.escape_input(req.body.title)
|
||||||
|
const content = req.body.content
|
||||||
|
const tags = func.escape_input(req.body.tags).split(",")
|
||||||
|
const delete_bool = req.body.delete
|
||||||
|
const unix_timestamp = getUnixTime(new Date())
|
||||||
|
console.log(users[userID]['prettyname'], "is editting the post titled:", title);
|
||||||
|
|
||||||
|
if (users[userID]['hash'] == password) { // password matches
|
||||||
|
let post = posts[postID]
|
||||||
|
post['title'] = title
|
||||||
|
post['content'] = content
|
||||||
|
post['tags'] = tags
|
||||||
|
post['editdate'] = unix_timestamp
|
||||||
|
if (typeof delete_bool != "undefined") {
|
||||||
|
console.log("Deleting post!")
|
||||||
|
posts[postID] = {"id": post["id"], "deleted": true}
|
||||||
|
comments.comments[postID] = [];
|
||||||
|
fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8');
|
||||||
|
}
|
||||||
|
fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8');
|
||||||
|
res.redirect(302, "/");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.render("partials/message", {
|
||||||
|
message: locale.incorrect_password,
|
||||||
|
config,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}); // /submit_edit
|
||||||
|
|
||||||
|
app.listen(config.port, () => {
|
||||||
|
console.log(`Server is running at http://localhost:${config.port} webroot: ${config.root_path}`);
|
||||||
|
console.log("Running in: ", __dirname)
|
||||||
|
});
|
22
views/forms/edit_account.ejs
Normal file
22
views/forms/edit_account.ejs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.language %>
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="/submit_edit_user" method="POST">
|
||||||
|
<input name="userID" type="hidden" value="<%= userID %>">
|
||||||
|
<label><%= locale.password %>:</label><br/>
|
||||||
|
<input type="password" required id="password" name="password"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.prettyname %>:</label><br/>
|
||||||
|
<input name="prettyname" value="<%= user.prettyname %>"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.description %>:</label><br/>
|
||||||
|
<textarea name="description"><%= user.description %></textarea><br/><br/>
|
||||||
|
|
||||||
|
<label><%- locale.delete_account_confirmation %>: </label><input type="checkbox" name="agreement"><br/>
|
||||||
|
<input type="submit" value="Submit"><br/>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
27
views/forms/edit_post.ejs
Normal file
27
views/forms/edit_post.ejs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.language %>">
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="/submit_edit_post" method="POST" onsubmit="sha512password()">
|
||||||
|
<input name="userID" type="hidden" value="<%= post['userID'] %>">
|
||||||
|
<input name="postID" type="hidden" value="<%= post_id %>">
|
||||||
|
|
||||||
|
<label><%= locale.password %>:</label><br/>
|
||||||
|
<input type="password" required id="password" name="password"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.title %>:</label><br/>
|
||||||
|
<input value="<%=post['title'] %>" required name="title"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.post_content %>:</label><br/>
|
||||||
|
<textarea required name="content"><%= post['content'] %></textarea><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.tags %>:</label><br/>
|
||||||
|
<input value="<%= post['tags'] %>" name="tags"><br/><br/>
|
||||||
|
|
||||||
|
<label>Delete forever (no undo): </label><input name="delete" type="checkbox"><br/>
|
||||||
|
<input type="submit" value="Submit"><br/>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
25
views/forms/new_post.ejs
Normal file
25
views/forms/new_post.ejs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
</html>
|
||||||
|
<head>
|
||||||
|
<%- include('../partials/head.ejs') %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="/submit_post" method="POST">
|
||||||
|
<label><%= locale.username %>:</label><br/>
|
||||||
|
<input required name="username"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.password %>:</label><br/>
|
||||||
|
<input type="password" required id="password" name="password"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.title %>:</label><br/>
|
||||||
|
<input required name="title"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.post_content %>:</label><br/>
|
||||||
|
<textarea required name="content"></textarea><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.tags %>:</label><br/>
|
||||||
|
<input name="tags"><br/><br/>
|
||||||
|
|
||||||
|
<input type="submit" value="Submit"><br/>
|
||||||
|
</body>
|
||||||
|
</form></html>
|
24
views/forms/signup.ejs
Normal file
24
views/forms/signup.ejs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
</html lang="<%= config.language %>">
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="/submit_signup" method="POST">
|
||||||
|
<label><%= locale.username %></label><br/>
|
||||||
|
<input required name="username"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.prettyname %></label><br/>
|
||||||
|
<input required name="prettyname"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.password %></label><br/>
|
||||||
|
<input type="password" required id="password" name="password"><br/><br/>
|
||||||
|
|
||||||
|
<label><%= locale.description %></label><br/>
|
||||||
|
<textarea id="description" name="description"></textarea><br/><br/>
|
||||||
|
|
||||||
|
<label><%- locale.signup_agreement %>: </label><input type="checkbox" name="agreement" required><br/>
|
||||||
|
<input type="submit" value="Submit"><br/>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
5
views/headers/site_wide.ejs
Normal file
5
views/headers/site_wide.ejs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<a href="/"><%= locale.home_page %></a>
|
||||||
|
<a href="/index/pages"><%= locale.site_index %></a>
|
||||||
|
<a href="<%= config.new_post_url %>"><%= locale.new_post %></a>
|
||||||
|
<br/>
|
||||||
|
<%- config.seperator %>
|
4
views/headers/tag.ejs
Normal file
4
views/headers/tag.ejs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<h1>
|
||||||
|
<%= locale.posts_tagged %>: "<%- tag %>"
|
||||||
|
</h1>
|
||||||
|
<%- config.seperator %>
|
20
views/headers/timeline.ejs
Normal file
20
views/headers/timeline.ejs
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<h1>
|
||||||
|
<%- config.site_name %>
|
||||||
|
</h1>
|
||||||
|
<h2>
|
||||||
|
<%- config.site_description %>
|
||||||
|
</h2>
|
||||||
|
<% if (config.rss == true) { %>
|
||||||
|
<a href="/rss"><%= locale.rss_feed %></a><br/>
|
||||||
|
<% } %>
|
||||||
|
<% if (config.atom == true) { %>
|
||||||
|
<a href="/atom"><%= locale.atom_feed %></a><br/>
|
||||||
|
<% } %>
|
||||||
|
<a href="<%= config.new_post_url %>"><%= locale.new_post %></a><br/>
|
||||||
|
<% if (config.allow_signup == true) { %>
|
||||||
|
<a href="<%= config.signup_url %>"><%= locale.sign_up %></a><br/>
|
||||||
|
<% } %>
|
||||||
|
<% if (config.enable_hitcount == true) { %>
|
||||||
|
<%= locale.hitcount %>: <%= hitcount %>
|
||||||
|
<% } %>
|
||||||
|
<%- config.seperator %>
|
8
views/headers/user.ejs
Normal file
8
views/headers/user.ejs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<h1>
|
||||||
|
<%= user.prettyname %>
|
||||||
|
</h1>
|
||||||
|
<p><%- func.render_md(user.description) %></p>
|
||||||
|
<a href="<%= config.edit_account_base_url %>/<%= userID %>"><%= locale.edit_account %></a><br/>
|
||||||
|
<a href="/user/<%= user.username %>/rss"><%= locale.rss_feed %></a><br/>
|
||||||
|
<a href="/user/<%= user.username %>/atom"><%= locale.atom_feed %></a>
|
||||||
|
<%- config.seperator %>
|
47
views/indexes/all_pages.ejs
Normal file
47
views/indexes/all_pages.ejs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.charset %>">
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Misc:<br/>
|
||||||
|
<a href="/">Home Page</a><br/>
|
||||||
|
<a href="<%= config.new_post_url %>">New Post Form</a><br/>
|
||||||
|
<a href="<%= config.signup_url %>">Signup Form</a><br/>
|
||||||
|
Indexes:<br/>
|
||||||
|
<a href="/index/posts">Posts Index</a><br/>
|
||||||
|
<a href="/index/users">Users Index</a><br/>
|
||||||
|
<a href="/index/comments">Comments Index</a><br/>
|
||||||
|
Posts:<br/>
|
||||||
|
<% for (let postID = 0; postID < posts.length; postID++) { %>
|
||||||
|
<% if (posts[postID]["deleted"] != true) { %>
|
||||||
|
<a href="/post/<%= postID %>"><%= posts[postID]["title"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
Comments:<br/>
|
||||||
|
<% for (let postID = 0; postID < comments.length; postID++) { %>
|
||||||
|
<% for (let comment_index = 0; comment_index < comments[postID].length; comment_index++) { %>
|
||||||
|
<a href="/comment/<%= comments[postID][comment_index]["id"] %>"><%= comments[postID][comment_index]["id"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
Users:<br/>
|
||||||
|
<% for (let userID = 0; userID < users.length; userID++) { %>
|
||||||
|
<% if (users[userID]["deleted"] != true) { %>
|
||||||
|
<a href="/user/<%= users[userID]["username"] %>"><%= users[userID]["username"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
Edit Posts:<br/>
|
||||||
|
<% for (let postID = 0; postID < posts.length; postID++) { %>
|
||||||
|
<% if (posts[postID]["deleted"] != true) { %>
|
||||||
|
<a href="/<%= config.edit_post_base_url %>/<%= postID %>">Edit <%= posts[postID]["title"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
Edit Users:<br/>
|
||||||
|
<% for (let userID = 0; userID < users.length; userID++) { %>
|
||||||
|
<% if (users[userID]["deleted"] != true) { %>
|
||||||
|
<a href="/<%= config.edit_account_base_url %>/<%= users[userID]["username"] %>">Edit <%= users[userID]["username"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
<!-- TODO add tags -->
|
||||||
|
</body>
|
||||||
|
</html>
|
13
views/indexes/comments.ejs
Normal file
13
views/indexes/comments.ejs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.charset %>">
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<% for (let postID = 0; postID < comments.length; postID++) { %>
|
||||||
|
<% for (let comment_index = 0; comment_index < comments[postID].length; comment_index++) { %>
|
||||||
|
<a href="/comment/<%= comments[postID][comment_index]["id"] %>"><%= comments[postID][comment_index]["id"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
</body>
|
||||||
|
</html>
|
13
views/indexes/posts.ejs
Normal file
13
views/indexes/posts.ejs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.charset %>">
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<% for (let postID = 0; postID < posts.length; postID++) { %>
|
||||||
|
<% if (posts[postID]["deleted"] != true) { %>
|
||||||
|
<a href="/post/<%= postID %>"><%= posts[postID]["title"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
</body>
|
||||||
|
</html>
|
13
views/indexes/users.ejs
Normal file
13
views/indexes/users.ejs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.charset %>">
|
||||||
|
<head>
|
||||||
|
<%- include("../partials/head") %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<% for (let userID = 0; userID < users.length; userID++) { %>
|
||||||
|
<% if (users[userID]["deleted"] != true) { %>
|
||||||
|
<a href="/user/<%= users[userID]["username"] %>"><%= users[userID]["username"] %></a><br/>
|
||||||
|
<% }; %>
|
||||||
|
<% }; %>
|
||||||
|
</body>
|
||||||
|
</html>
|
14
views/pages/comment.ejs
Normal file
14
views/pages/comment.ejs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<%- include('../partials/head'); %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<%- include("../headers/site_wide") %>
|
||||||
|
</div>
|
||||||
|
<div id="comment">
|
||||||
|
<%- include("../partials/comment"); %>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
17
views/pages/post.ejs
Normal file
17
views/pages/post.ejs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<%- include('../partials/head'); %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<%- include("../headers/site_wide") %>
|
||||||
|
</div>
|
||||||
|
<div id="posts">
|
||||||
|
<%- include('../posts/post'); %>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<%- include('../partials/footer'); %>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
26
views/pages/tag.ejs
Normal file
26
views/pages/tag.ejs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<%- include('../partials/head'); %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<%- include('../headers/site_wide'); %>
|
||||||
|
<%- include('../headers/tag'); %>
|
||||||
|
</div>
|
||||||
|
<div id="posts">
|
||||||
|
<% for (let index = posts.length - 1; index >= 0; index--) { %>
|
||||||
|
<% if ( posts[index].deleted != true) { %>
|
||||||
|
<% posts[index].tags.forEach((current_tag, tag_index) => { %>
|
||||||
|
<% if (current_tag == tag) { %>
|
||||||
|
<%- include('../posts/tag', {post: posts[index], user: users[posts[index].userID], comments: comments[index]}); %>
|
||||||
|
<% } %>
|
||||||
|
<% }) %>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<%- include('../partials/footer'); %>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
29
views/pages/timeline.ejs
Normal file
29
views/pages/timeline.ejs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<%- include('../partials/head'); %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<%- include("../headers/site_wide") %>
|
||||||
|
<%- include('../headers/timeline'); %>
|
||||||
|
</div>
|
||||||
|
<form method="POST" action="/submit_nothing" style="display:none">
|
||||||
|
<!-- Form is used to help mitigate spam as it is the first form on the front page -->
|
||||||
|
<input type="hidden" name="post_index" value="0">
|
||||||
|
<input placeholder="username" name="name"><br/>
|
||||||
|
<textarea placeholder="comment" name="content"></textarea><br/>
|
||||||
|
<button type="submit">Submit</button>
|
||||||
|
</form>
|
||||||
|
<div id="posts">
|
||||||
|
<% for (let index = posts.length - 1; index >= 0; index--) { %>
|
||||||
|
<% if (posts[index]["deleted"] != true) { %>
|
||||||
|
<%- include('../posts/timeline', {post: posts[index], postID: index, user: users[posts[index].userID], comments: comments[index]}); %>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<%- include('../partials/footer'); %>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
22
views/pages/user.ejs
Normal file
22
views/pages/user.ejs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<%- include('../partials/head'); %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<%- include("../headers/site_wide") %>
|
||||||
|
<%- include('../headers/user'); %>
|
||||||
|
</div>
|
||||||
|
<div id="posts">
|
||||||
|
<% 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]}); %>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
<footer>
|
||||||
|
<%- include('../partials/footer'); %>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
3
views/partials/comment.ejs
Normal file
3
views/partials/comment.ejs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<b><%= comment.name %></b> <%= func.unix_time_to_date_format(comment.pubdate) %> <i>No. <%= comment.id %></i>:<br/>
|
||||||
|
<%- func.render_comment(comment.content) %>
|
||||||
|
<br/>
|
3
views/partials/footer.ejs
Normal file
3
views/partials/footer.ejs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<%= locale.site_ran_by %> <%= config.site_admin %><br/>
|
||||||
|
<%- locale.attribution %><br/>
|
||||||
|
<%= locale.AI_consent %> <!-- remove consent for AI scrapers -->
|
8
views/partials/head.ejs
Normal file
8
views/partials/head.ejs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<meta charset="<%- config.charset %>">
|
||||||
|
<title><%= config.site_name %></title>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/custom.css">
|
13
views/partials/message.ejs
Normal file
13
views/partials/message.ejs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="<%= config.language %>">
|
||||||
|
<head>
|
||||||
|
<%- include('head') %>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="header">
|
||||||
|
<%- include("../headers/site_wide") %>
|
||||||
|
</div>
|
||||||
|
<%- message %>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
48
views/posts/post.ejs
Normal file
48
views/posts/post.ejs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<div id="post-header">
|
||||||
|
<h1>
|
||||||
|
<%= post.title %>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div id="post-content">
|
||||||
|
<p>
|
||||||
|
<%- func.render_md(post.content) %><br/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div id="post-details">
|
||||||
|
<div id="post-author">
|
||||||
|
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/></i>
|
||||||
|
</div>
|
||||||
|
<div id="post-tags">
|
||||||
|
<%- func.render_tags(post.tags) %><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-edit">
|
||||||
|
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-pubdate">
|
||||||
|
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-editdate">
|
||||||
|
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-commentform">
|
||||||
|
<!-- Comment form -->
|
||||||
|
<form method="POST" action="/submit_comment">
|
||||||
|
<input type="hidden" name="post_index" value="<%= post["id"] %>">
|
||||||
|
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
|
||||||
|
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
|
||||||
|
<button type="submit"><%= locale.submit %></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-comments">
|
||||||
|
<% comments.forEach((comment, index) => { %>
|
||||||
|
<div id="comment-no<%= comment.id %>" class="post-comment-<%= index %>">
|
||||||
|
<%- include('../partials/comment', {comment: comment}) %>
|
||||||
|
</div>
|
||||||
|
<% }) %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%- config.seperator %>
|
||||||
|
|
51
views/posts/tag.ejs
Normal file
51
views/posts/tag.ejs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<div id="post-header">
|
||||||
|
<h1>
|
||||||
|
<%= post.title %>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div id="post-content">
|
||||||
|
<p>
|
||||||
|
<%- func.render_md(post.content) %><br/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div id="post-details">
|
||||||
|
<div id="post-author">
|
||||||
|
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/></i>
|
||||||
|
</div>
|
||||||
|
<div id="post-permalink">
|
||||||
|
<a href="/post/<%= post["id"] %>"><%= locale.permalink %><a/>
|
||||||
|
</div>
|
||||||
|
<div id="post-tags">
|
||||||
|
<%- func.render_tags(post.tags) %><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-edit">
|
||||||
|
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-pubdate">
|
||||||
|
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-editdate">
|
||||||
|
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-commentform">
|
||||||
|
<!-- Comment form -->
|
||||||
|
<form method="POST" action="/submit_comment">
|
||||||
|
<input type="hidden" name="post_index" value="<%= post["id"] %>">
|
||||||
|
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
|
||||||
|
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
|
||||||
|
<button type="submit"><%= locale.submit %></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-comments">
|
||||||
|
<% comments.forEach((comment, index) => { %>
|
||||||
|
<div id="comment-no<%= comment.id %>" class="post-comment-<%= index %>">
|
||||||
|
<%- include('../partials/comment', {comment: comment}) %>
|
||||||
|
</div>
|
||||||
|
<% }) %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%- config.seperator %>
|
||||||
|
|
51
views/posts/timeline.ejs
Normal file
51
views/posts/timeline.ejs
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<div id="post-header">
|
||||||
|
<h1>
|
||||||
|
<%= post.title %>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div id="post-content">
|
||||||
|
<p>
|
||||||
|
<%- func.render_md(post.content) %><br/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div id="post-details">
|
||||||
|
<div id="post-author">
|
||||||
|
<i><%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/></i>
|
||||||
|
</div>
|
||||||
|
<div id="post-permalink">
|
||||||
|
<a href="/post/<%= post["id"] %>"><%= locale.permalink %><a/>
|
||||||
|
</div>
|
||||||
|
<div id="post-tags">
|
||||||
|
<%- func.render_tags(post.tags) %><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-edit">
|
||||||
|
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-pubdate">
|
||||||
|
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-editdate">
|
||||||
|
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-commentform">
|
||||||
|
<!-- Comment form -->
|
||||||
|
<form method="POST" action="/submit_comment">
|
||||||
|
<input type="hidden" name="post_index" value="<%= post["id"] %>">
|
||||||
|
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
|
||||||
|
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
|
||||||
|
<button type="submit"><%= locale.submit %></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-comments">
|
||||||
|
<% comments.forEach((comment, index) => { %>
|
||||||
|
<div id="comment-no<%= comment.id %>" class="post-comment-<%= index %>">
|
||||||
|
<%- include('../partials/comment', {comment: comment}) %>
|
||||||
|
</div>
|
||||||
|
<% }) %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%- config.seperator %>
|
||||||
|
|
48
views/posts/user.ejs
Normal file
48
views/posts/user.ejs
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<div id="post-header">
|
||||||
|
<h1>
|
||||||
|
<%= post.title %>
|
||||||
|
</h1>
|
||||||
|
</div>
|
||||||
|
<div id="post-content">
|
||||||
|
<p>
|
||||||
|
<%- func.render_md(post.content) %><br/>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div id="post-details">
|
||||||
|
<div id="post-permalink">
|
||||||
|
<a href="/post/<%= post["id"] %>"><%= locale.permalink %><a/>
|
||||||
|
</div>
|
||||||
|
<div id="post-tags">
|
||||||
|
<%- func.render_tags(post.tags) %><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-edit">
|
||||||
|
<a href="<%= config.edit_post_base_url %>/<%= post["id"] %>"><%= locale.edit_post %></a><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-pubdate">
|
||||||
|
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
<div id="post-editdate">
|
||||||
|
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-commentform">
|
||||||
|
<!-- Comment form -->
|
||||||
|
<form method="POST" action="/submit_comment">
|
||||||
|
<input type="hidden" name="post_index" value="<%= post["id"] %>">
|
||||||
|
<label><%= locale.username %>:</label><br/><input name="name"><br/><br/>
|
||||||
|
<label><%= locale.comment %>:</label><br/><textarea name="content"></textarea><br/>
|
||||||
|
<button type="submit"><%= locale.submit %></button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="post-comments">
|
||||||
|
<% comments.forEach((comment, index) => { %>
|
||||||
|
<div id="comment-no<%= comment.id %>" class="post-comment-<%= index %>">
|
||||||
|
<%- include('../partials/comment', {comment: comment}) %>
|
||||||
|
</div>
|
||||||
|
<% }) %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%- config.seperator %>
|
||||||
|
|
22
views/syndication/global_atom.ejs
Normal file
22
views/syndication/global_atom.ejs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?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]["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>
|
22
views/syndication/global_rss.ejs
Normal file
22
views/syndication/global_rss.ejs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?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]["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>
|
||||||
|
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
||||||
|
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
||||||
|
<% } %>
|
||||||
|
</item>
|
||||||
|
<% } %>
|
||||||
|
<% } %>
|
||||||
|
</channel>
|
||||||
|
</rss>
|
24
views/syndication/user_atom.ejs
Normal file
24
views/syndication/user_atom.ejs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?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>
|
24
views/syndication/user_rss.ejs
Normal file
24
views/syndication/user_rss.ejs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?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>
|
||||||
|
<% 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