diff --git a/example-config.json b/example-config.json index 9c1cf7e..d948737 100644 --- a/example-config.json +++ b/example-config.json @@ -3,6 +3,7 @@ "seperator": "
", "site_name": "My Blog", "site_url": "https://example.com", + "site_path": "/", "locale": "en-US", "port": 8080, "data_storage": "json", @@ -13,10 +14,10 @@ "enable_hitcount": true, "charset": "UTF-8", "root_path": "../webroot/", - "edit_account_base_url": "/edit_account", - "new_post_url": "/post", - "signup_url": "/signup", - "edit_post_base_url": "/edit", + "edit_account_base_url": "edit_account", + "new_post_url": "post", + "signup_url": "signup", + "edit_post_base_url": "edit", "default_commenter_username": "Anon", "rss": true, "atom": true, diff --git a/src/routes/form_actions.js b/src/routes/form_actions.js index 688f0da..5e97d4d 100644 --- a/src/routes/form_actions.js +++ b/src/routes/form_actions.js @@ -14,7 +14,7 @@ const crypto = require('crypto') const router = express.Router(); ////////////////////// Form actions ///////////////////////// -router.post("/submit_comment", (req,res) => { +router.post(`${config.site_path}/submit_comment`, (req,res) => { const unix_timestamp = getUnixTime(new Date()) const postID = parseInt(req.body.post_index) const content = func.escape_input(req.body.content) @@ -38,10 +38,10 @@ router.post("/submit_comment", (req,res) => { fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8'); } - res.redirect(301,`/post/${req.body.post_index}`) + res.redirect(301,`${config.site_path}/post/${req.body.post_index}`) }); // /submit_comment -router.post("/submit_post", (req,res) => { +router.post(`${config.site_path}/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) @@ -71,7 +71,7 @@ router.post("/submit_post", (req,res) => { fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8'); comments.push({'id': id, 'comments': []}) fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`) - res.redirect(302, "/"); + res.redirect(302, config.site_path); } else { res.render("partials/message", { @@ -81,7 +81,7 @@ router.post("/submit_post", (req,res) => { } }); // /submit_post -router.post("/submit_signup", (req,res) => { +router.post(`${config.site_path}/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) @@ -100,7 +100,7 @@ router.post("/submit_signup", (req,res) => { "description": description, }) fs.writeFileSync(`../data/users.json`, `${JSON.stringify(users)}`, 'utf-8'); - res.redirect(301, `/user/${username}`) + res.redirect(301, `${config.site_path}/user/${username}`) } // if the user does exist then else { @@ -118,12 +118,12 @@ router.post("/submit_signup", (req,res) => { } // If allow_signup is undefined or not a boolean, error else { - res.redirect(301,"/") + res.redirect(301,config.site_path) console.log("Error, invalid value for allow_signup (bool)") } }); // /submit_signup -router.post("/submit_edit_user", (req,res) => { +router.post(`${config.site_path}/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) @@ -152,7 +152,7 @@ router.post("/submit_edit_user", (req,res) => { 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"]}`) + res.redirect(301,`${config.site_path}/user/${users[userID]["username"]}`) } else { // password does not match res.render("partials/message", { @@ -170,7 +170,7 @@ router.post("/submit_edit_user", (req,res) => { } }); // /submit_delete_account -router.post("/submit_edit_post", (req,res) => { +router.post(`${config.site_path}/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 @@ -194,7 +194,7 @@ router.post("/submit_edit_post", (req,res) => { fs.writeFileSync(`../data/comments.json`, `${JSON.stringify(comments)}`, 'utf-8'); } fs.writeFileSync(`../data/posts.json`, `${JSON.stringify(posts)}`, 'utf-8'); - res.redirect(302, "/"); + res.redirect(302, config.site_path); } else { res.render("partials/message", { @@ -204,7 +204,7 @@ router.post("/submit_edit_post", (req,res) => { } }); // /submit_edit -router.get('/search', (req, res) => { +router.get(`${config.site_path}/search`, (req, res) => { const search_term = func.escape_input(req.query.q); // 'q' is the parameter name let search_type = req.query.type; // eg 'post', 'user' if (typeof search_type == 'string') { // Make the search_term an array diff --git a/src/routes/forms.js b/src/routes/forms.js index 568145b..de5cd3e 100644 --- a/src/routes/forms.js +++ b/src/routes/forms.js @@ -5,13 +5,13 @@ const func = require('../functions') const router = express.Router(); ///////////////////// Form pages //////////////////////////// -router.get(config.new_post_url, (req,res) => { +router.get(`${config.site_path}/${config.new_post_url}`, (req,res) => { res.render("forms/new_post", { config, locale, }); }); // /post -router.get(config.signup_url, (req,res) => { +router.get(`${config.site_path}/${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 @@ -33,7 +33,7 @@ router.get(config.signup_url, (req,res) => { console.log("Error, invalid value for allow_signup (bool)") } }); // /signup -router.get(`${config.edit_account_base_url}/:user_id`, (req,res) => { +router.get(`${config.site_path}/${config.edit_account_base_url}/:user_id`, (req,res) => { const userID = parseInt(req.params.user_id); res.render("forms/edit_account", { config, @@ -42,7 +42,7 @@ router.get(`${config.edit_account_base_url}/:user_id`, (req,res) => { userID }); }); // /delete_account -router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => { +router.get(`${config.site_path}/${config.edit_post_base_url}/:post_id`, (req,res) => { const postID = req.params.post_id const post = data.getdata('posts','id', postID) const user = data.getdata('users', 'id', post.userID) diff --git a/src/routes/indexes.js b/src/routes/indexes.js index 6c3cbbb..4fb6e2d 100644 --- a/src/routes/indexes.js +++ b/src/routes/indexes.js @@ -6,7 +6,7 @@ const func = require('../functions') const router = express.Router(); ///////////////////// Page index's /////////////////////// -router.get("/index/pages", (req,res) => { +router.get(`${config.site_path}/index/pages`, (req,res) => { res.render("indexes/all_pages", { config, posts: data.getdata('posts'), @@ -14,19 +14,19 @@ router.get("/index/pages", (req,res) => { comments: data.getdata('comments'), }); }); // /index/pages -router.get("/index/posts", (req,res) => { +router.get(`${config.site_path}/index/posts`, (req,res) => { res.render("indexes/posts", { config, posts: data.getdata('posts'), }); }); // /index/posts -router.get("/index/users", (req,res) => { +router.get(`${config.site_path}/index/users`, (req,res) => { res.render("indexes/users", { config, users: data.getdata('users'), }); }); // /index/users -router.get("/index/comments", (req,res) => { +router.get(`${config.site_path}/index/comments`, (req,res) => { res.render("indexes/comments", { config, comments: data.getdata('comments'), diff --git a/src/routes/standard_pages.js b/src/routes/standard_pages.js index 6133347..3d82371 100644 --- a/src/routes/standard_pages.js +++ b/src/routes/standard_pages.js @@ -9,7 +9,7 @@ const router = express.Router(); ///////////////////// Standard Pages ////////////////////// // Timeline -router.get("/", (req,res) => { +router.get(config.site_path, (req,res) => { // Increment the hitcount if (config.enable_hitcount) { data.increment_hitcount() @@ -31,7 +31,7 @@ router.get("/", (req,res) => { }); // / // Users -router.get("/user/:username", (req, res) => { +router.get(`${config.site_path}/user/:username`, (req, res) => { const userID = func.get_userID(req.params.username) let user = data.getdata('users', 'id', userID) if (userID != -1) { @@ -59,7 +59,7 @@ router.get("/user/:username", (req, res) => { }); // /user/:username // Posts -router.get("/post/:post_index", (req, res) => { +router.get(`${config.site_path}/post/:post_index`, (req, res) => { const postID = parseInt(req.params.post_index) let post = data.getdata('posts','id', postID) if (post == 1) { // data.getdata returns error code 1 if nothing is available @@ -94,7 +94,7 @@ router.get("/post/:post_index", (req, res) => { // Tags -router.get("/tag/:tag", (req,res) => { +router.get(`${config.site_path}/tag/:tag`, (req,res) => { const tag = req.params.tag res.render("pages/tag", { @@ -113,7 +113,7 @@ router.get("/tag/:tag", (req,res) => { // Comments -router.get("/comment/:postID-:commentID", (req,res) => { +router.get(`${config.site_path}/comment/:postID-:commentID`, (req,res) => { const commentID = parseInt(req.params.commentID); const postID = parseInt(req.params.postID); diff --git a/src/routes/syndication.js b/src/routes/syndication.js index 9e8bb80..15ce3e5 100644 --- a/src/routes/syndication.js +++ b/src/routes/syndication.js @@ -9,7 +9,7 @@ const router = express.Router(); ////////////////////// SYNDICATION //////////////////////// // global RSS protocol gets -router.get("/rss", (req,res) => { +router.get(`${config.site_path}/rss`, (req,res) => { if (config.rss == false) { res.render("partials/message", { message: locale.rss_disabled, @@ -26,7 +26,7 @@ router.get("/rss", (req,res) => { }; }); // user RSS protocol gets -router.get("/user/:username/rss", (req,res) => { +router.get(`${config.site_path}/user/:username/rss`, (req,res) => { const username = req.params.username; const userID = func.get_userID(username); if (config.rss == false) { @@ -46,7 +46,7 @@ router.get("/user/:username/rss", (req,res) => { }; }); // global ATOM protocol gets -router.get("/atom", (req,res) => { +router.get(`${config.site_path}/atom`, (req,res) => { if (config.atom == false) { res.render("partials/message", { message: locale.atom_disabled, @@ -64,7 +64,7 @@ router.get("/atom", (req,res) => { }; }); // user ATOM protocol gets -router.get("/user/:username/atom", (req,res) => { +router.get(`${config.site_path}/user/:username/atom`, (req,res) => { const username = req.params.username; const userID = func.get_userID(username); if (config.atom == false) { diff --git a/views/forms/edit_account.ejs b/views/forms/edit_account.ejs index 5ab96f6..e966c93 100644 --- a/views/forms/edit_account.ejs +++ b/views/forms/edit_account.ejs @@ -4,7 +4,7 @@ <%- include("../partials/head") %> -
+


diff --git a/views/forms/edit_post.ejs b/views/forms/edit_post.ejs index 72429aa..9ec81ae 100644 --- a/views/forms/edit_post.ejs +++ b/views/forms/edit_post.ejs @@ -4,7 +4,7 @@ <%- include("../partials/head") %> - + diff --git a/views/forms/new_post.ejs b/views/forms/new_post.ejs index 8ff7420..bec5a82 100644 --- a/views/forms/new_post.ejs +++ b/views/forms/new_post.ejs @@ -4,7 +4,7 @@ <%- include('../partials/head.ejs') %> - +


diff --git a/views/forms/signup.ejs b/views/forms/signup.ejs index c76c7fc..40b48f3 100644 --- a/views/forms/signup.ejs +++ b/views/forms/signup.ejs @@ -4,7 +4,7 @@ <%- include("../partials/head") %> - +


diff --git a/views/headers/site_wide.ejs b/views/headers/site_wide.ejs index 97d091e..aa6e447 100644 --- a/views/headers/site_wide.ejs +++ b/views/headers/site_wide.ejs @@ -1,28 +1,29 @@ -<%= locale.home_page %> +<%= locale.home_page %> / <% if (config.rss == true) { %> - - <%= locale.rss_feed %> + + <%= locale.rss_feed %> <% } %> +| <% if (config.atom == true) { %> - - <%= locale.atom_feed %> + + <%= locale.atom_feed %> <% } %> / -<%= locale.new_post %> +<%= locale.new_post %> / <% if (config.allow_signup == true) { %> - <%= locale.sign_up %> + <%= locale.sign_up %> <% } %> / - +

-

<%= config.site_name %>

+

<%= config.site_name %>

<%- config.site_description %>

diff --git a/views/headers/user.ejs b/views/headers/user.ejs index 2c128c9..dfab4f7 100644 --- a/views/headers/user.ejs +++ b/views/headers/user.ejs @@ -4,14 +4,14 @@

<%- func.render_md(user.description) %>

- - <%= locale.edit_account %> + + <%= locale.edit_account %> | - - <%= locale.rss_feed %> + + <%= locale.rss_feed %> - - <%= locale.atom_feed %> + + <%= locale.atom_feed %> <%- config.seperator %> diff --git a/views/indexes/all_pages.ejs b/views/indexes/all_pages.ejs index f02e3d9..c545991 100644 --- a/views/indexes/all_pages.ejs +++ b/views/indexes/all_pages.ejs @@ -5,41 +5,41 @@ Misc:
- Home Page
- New Post Form
- Signup Form
+ Home Page
+ New Post Form
+ Signup Form
Indexes:
- Posts Index
- Users Index
- Comments Index
+ Posts Index
+ Users Index
+ Comments Index
Posts:
<% for (let postID = 0; postID < posts.length; postID++) { %> <% if (posts[postID]["deleted"] != true) { %> - <%= posts[postID]["title"] %>
+ <%= posts[postID]["title"] %>
<% }; %> <% }; %> Comments:
<% for (let postID = 0; postID < comments.length; postID++) { %> <% for (let comment_index = 0; comment_index < comments[postID]['comments'].length; comment_index++) { %> - <%= postID %>-<%= comment_index %>
+ <%= postID %>-<%= comment_index %>
<% }; %> <% }; %> Users:
<% for (let userID = 0; userID < users.length; userID++) { %> <% if (users[userID]["deleted"] != true) { %> - "><%= users[userID]["username"] %>
+ "><%= users[userID]["username"] %>
<% }; %> <% }; %> Edit Posts:
<% for (let postID = 0; postID < posts.length; postID++) { %> <% if (posts[postID]["deleted"] != true) { %> - Edit <%= posts[postID]["title"] %>
+ Edit <%= posts[postID]["title"] %>
<% }; %> <% }; %> Edit Users:
<% for (let userID = 0; userID < users.length; userID++) { %> <% if (users[userID]["deleted"] != true) { %> - ">Edit <%= users[userID]["username"] %>
+ ">Edit <%= users[userID]["username"] %>
<% }; %> <% }; %> diff --git a/views/indexes/comments.ejs b/views/indexes/comments.ejs index 1e064f6..0e7a5c8 100644 --- a/views/indexes/comments.ejs +++ b/views/indexes/comments.ejs @@ -6,7 +6,7 @@ <% for (let postID = 0; postID < comments.length; postID++) { %> <% for (let comment_index = 0; comment_index < comments[postID]['comments'].length; comment_index++) { %> - <%= postID %>-<%= comment_index %>
+ <%= postID %>-<%= comment_index %>
<% }; %> <% }; %> diff --git a/views/indexes/posts.ejs b/views/indexes/posts.ejs index fdf2116..1e14659 100644 --- a/views/indexes/posts.ejs +++ b/views/indexes/posts.ejs @@ -6,7 +6,7 @@ <% for (let postID = 0; postID < posts.length; postID++) { %> <% if (posts[postID]["deleted"] != true) { %> - <%= posts[postID]["title"] %>
+ <%= posts[postID]["title"] %>
<% }; %> <% }; %> diff --git a/views/indexes/users.ejs b/views/indexes/users.ejs index d868d8e..61ea6fd 100644 --- a/views/indexes/users.ejs +++ b/views/indexes/users.ejs @@ -6,7 +6,7 @@ <% for (let userID = 0; userID < users.length; userID++) { %> <% if (users[userID]["deleted"] != true) { %> - "><%= users[userID]["username"] %>
+ "><%= users[userID]["username"] %>
<% }; %> <% }; %> diff --git a/views/partials/comment.ejs b/views/partials/comment.ejs index a9dd610..8d63137 100644 --- a/views/partials/comment.ejs +++ b/views/partials/comment.ejs @@ -5,7 +5,7 @@ <%= func.unix_time_to_date_format(comment.pubdate) %> - No. <%= postID %>-<%= comment.id %>:
+ No. <%= postID %>-<%= comment.id %>:
<%- func.render_comment(comment.content) %> diff --git a/views/partials/footer.ejs b/views/partials/footer.ejs index 0e1b0fe..466dacd 100644 --- a/views/partials/footer.ejs +++ b/views/partials/footer.ejs @@ -1,4 +1,4 @@ -<%= locale.site_index %>
+<%= locale.site_index %>
<%= locale.site_ran_by %> <%= config.site_admin %>
<%- locale.attribution %>
<%= locale.AI_consent %> diff --git a/views/partials/head.ejs b/views/partials/head.ejs index 98c1fda..16f66e8 100644 --- a/views/partials/head.ejs +++ b/views/partials/head.ejs @@ -1,10 +1,10 @@ -<%= config.site_name %> +<%= config.site_path %> - - + + diff --git a/views/posts/post.ejs b/views/posts/post.ejs index f61a0ee..cbbd86e 100644 --- a/views/posts/post.ejs +++ b/views/posts/post.ejs @@ -1,6 +1,6 @@

- '><%= post.title %> + '><%= post.title %>

@@ -15,7 +15,7 @@
- <%= locale.written_by %> <%= user.prettyname %> + <%= locale.written_by %> <%= user.prettyname %> - @@ -25,8 +25,8 @@ <%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %>
- "> - <%= locale.edit_post %> + "> + <%= locale.edit_post %>
<% if (config.enable_hitcount == true) { %> @@ -40,7 +40,7 @@
-
+ ">




diff --git a/views/posts/tag.ejs b/views/posts/tag.ejs index bcd1f8a..ac00a0d 100644 --- a/views/posts/tag.ejs +++ b/views/posts/tag.ejs @@ -1,6 +1,6 @@

- '><%= post.title %> + '><%= post.title %>

@@ -15,7 +15,7 @@
- <%= user.prettyname %> + <%= user.prettyname %> - @@ -24,7 +24,7 @@
"> - <%= locale.edit_post %> + <%= locale.edit_post %>
diff --git a/views/posts/timeline.ejs b/views/posts/timeline.ejs index 6f61b5c..a687428 100644 --- a/views/posts/timeline.ejs +++ b/views/posts/timeline.ejs @@ -1,6 +1,6 @@

- '><%= post.title %> + '><%= post.title %>

@@ -15,11 +15,11 @@
- <%= user.prettyname %> + <%= user.prettyname %> - - - <%= locale.edit_account %> + + <%= locale.edit_account %> - @@ -27,8 +27,8 @@
- "> - <%= locale.edit_post %> + "> + <%= locale.edit_post %>
diff --git a/views/posts/user.ejs b/views/posts/user.ejs index 5c69c4f..502a7e0 100644 --- a/views/posts/user.ejs +++ b/views/posts/user.ejs @@ -1,6 +1,6 @@

- '><%= post.title %> + '><%= post.title %>

@@ -15,7 +15,7 @@
- <%= user.prettyname %> + <%= user.prettyname %> - @@ -23,8 +23,8 @@
- "> - <%= locale.edit_post %> + "> + <%= locale.edit_post %>