This commit is contained in:
deadvey 2025-07-10 20:32:30 +01:00
parent 61b0d8ec7f
commit 68068adfa3
4 changed files with 35 additions and 5 deletions

View File

@ -1,4 +1,5 @@
This is a blogging site written in nodejs, all pages are served directly by the nodejs backend.<br/>
Please don't use this yet, it's not finished<br/>
In action on my website: [deadvey.com](https://deadvey.com)<br/>
# features
@ -9,8 +10,11 @@ In action on my website: [deadvey.com](https://deadvey.com)<br/>
* timeline, user page, post page and tag specific page
* edit/delete posts
* probably insecure as hell
* hitcount
# planned features
* atom
* federation
* sign up
* Markdown syntax in posts
* All strings (including in edit and post page) customisable

22
app.js
View File

@ -7,6 +7,8 @@ const posts = require('./posts.js');
const config = require('./config.js');
const app = express();
const port = 8080;
let footer_div = config.site_wide_footer
footer_div = replace_format_indicators(footer_div)
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
@ -67,6 +69,11 @@ function replace_format_indicators(input_string, post_index=0, tag_name="tag") {
.replaceAll("%U", `/user/${users.users[post_object["userID"]]['username']}`)
.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
}
@ -105,6 +112,13 @@ app.get(config.rss_path, (req,res) => {
});
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 = "";
@ -115,7 +129,7 @@ app.get("/", (req,res) => {
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></html>`);
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", (req,res) => {
@ -161,13 +175,13 @@ app.get("/user/:username", (req, res) => {
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></html>`);
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></html>`);
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
@ -180,7 +194,7 @@ app.get("/tag/:tag", (req,res) => {
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></html>`);
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.post("/submit_edit", (req,res) => {

View File

@ -3,6 +3,7 @@ export const site_name = "Deadvey's Blog"
export const site_url = "https://deadvey.com"
export const site_description = "Films, tech, random shit"
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 = "/var/www/deadvey.com/blog"
@ -26,6 +27,7 @@ export const time_zone = "+0000"
// %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
// %N - the username of the user (poster)
@ -37,11 +39,13 @@ export const time_zone = "+0000"
// %U - URL the the user (poster)
// %Y - Site Name as defined by site_name
// %W - Site Description as defined by site_description
// %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
@ -59,7 +63,8 @@ export const post_page_format = `<h1>%T</h1>
<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>`
<i>Edited: %E</i>
%S`
export const timeline_post_format = `<h3>%T</h3>
<p>%C</p>
<a href="%L">Permalink</a><br/>
@ -71,6 +76,9 @@ export const tag_post_format = `<h3>%T</h3>
<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
@ -123,3 +131,6 @@ export const css = `
}
}
`
// 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>"

1
hitcount.txt Normal file
View File

@ -0,0 +1 @@
15