hitcount
This commit is contained in:
parent
61b0d8ec7f
commit
68068adfa3
@ -1,4 +1,5 @@
|
|||||||
This is a blogging site written in nodejs, all pages are served directly by the nodejs backend.<br/>
|
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/>
|
In action on my website: [deadvey.com](https://deadvey.com)<br/>
|
||||||
|
|
||||||
# features
|
# 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
|
* timeline, user page, post page and tag specific page
|
||||||
* edit/delete posts
|
* edit/delete posts
|
||||||
* probably insecure as hell
|
* probably insecure as hell
|
||||||
|
* hitcount
|
||||||
|
|
||||||
# planned features
|
# planned features
|
||||||
* atom
|
* atom
|
||||||
* federation
|
* federation
|
||||||
* sign up
|
* sign up
|
||||||
|
* Markdown syntax in posts
|
||||||
|
* All strings (including in edit and post page) customisable
|
||||||
|
22
app.js
22
app.js
@ -7,6 +7,8 @@ const posts = require('./posts.js');
|
|||||||
const config = require('./config.js');
|
const config = require('./config.js');
|
||||||
const app = express();
|
const app = express();
|
||||||
const port = 8080;
|
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.urlencoded({ extended: true }));
|
||||||
app.use(express.json());
|
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("%U", `/user/${users.users[post_object["userID"]]['username']}`)
|
||||||
.replaceAll("%Y", config.site_name)
|
.replaceAll("%Y", config.site_name)
|
||||||
.replaceAll("%W", config.site_description)
|
.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
|
return output_string
|
||||||
}
|
}
|
||||||
@ -105,6 +112,13 @@ app.get(config.rss_path, (req,res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
app.get("/", (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 = config.timeline_header
|
||||||
header_div = replace_format_indicators(header_div);
|
header_div = replace_format_indicators(header_div);
|
||||||
posts_div = "";
|
posts_div = "";
|
||||||
@ -115,7 +129,7 @@ app.get("/", (req,res) => {
|
|||||||
posts_div += replace_format_indicators(post, counter);
|
posts_div += replace_format_indicators(post, counter);
|
||||||
counter -= 1;
|
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) => {
|
app.get("/post", (req,res) => {
|
||||||
@ -161,13 +175,13 @@ app.get("/user/:username", (req, res) => {
|
|||||||
posts_div += replace_format_indicators(post, post_index);
|
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) => {
|
app.get("/post/:post_index", (req, res) => {
|
||||||
post_div = "";
|
post_div = "";
|
||||||
let post = config.post_page_format;
|
let post = config.post_page_format;
|
||||||
post_div += replace_format_indicators(post, req.params.post_index);
|
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) => {
|
app.get("/tag/:tag", (req,res) => {
|
||||||
const tag = req.params.tag
|
const tag = req.params.tag
|
||||||
@ -180,7 +194,7 @@ app.get("/tag/:tag", (req,res) => {
|
|||||||
page_content += replace_format_indicators(post, i);
|
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) => {
|
app.post("/submit_edit", (req,res) => {
|
||||||
|
13
config.js
13
config.js
@ -3,6 +3,7 @@ export const site_name = "Deadvey's Blog"
|
|||||||
export const site_url = "https://deadvey.com"
|
export const site_url = "https://deadvey.com"
|
||||||
export const site_description = "Films, tech, random shit"
|
export const site_description = "Films, tech, random shit"
|
||||||
export const timeline_length = 20
|
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
|
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.
|
// 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"
|
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
|
// %E - Edited date in the format specified by date_format
|
||||||
// %F - Pretty name
|
// %F - Pretty name
|
||||||
// %G - Tag name (used for the tag page only)
|
// %G - Tag name (used for the tag page only)
|
||||||
|
// %H - Frontpage hit count
|
||||||
// %I - User description
|
// %I - User description
|
||||||
// %L - URL Permanent link to the post
|
// %L - URL Permanent link to the post
|
||||||
// %N - the username of the user (poster)
|
// %N - the username of the user (poster)
|
||||||
@ -37,11 +39,13 @@ export const time_zone = "+0000"
|
|||||||
// %U - URL the the user (poster)
|
// %U - URL the the user (poster)
|
||||||
// %Y - Site Name as defined by site_name
|
// %Y - Site Name as defined by site_name
|
||||||
// %W - Site Description as defined by site_description
|
// %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>
|
export const timeline_header = `<h1>%Y</h1>
|
||||||
<h2>%W</h2>
|
<h2>%W</h2>
|
||||||
<a href="%P">Create Post</a><br/>
|
<a href="%P">Create Post</a><br/>
|
||||||
<a href="%R">RSS Feed</a><br/>
|
<a href="%R">RSS Feed</a><br/>
|
||||||
|
Hit count: %H
|
||||||
%S`
|
%S`
|
||||||
export const user_page_header = `<h1>%F's posts:</h1>
|
export const user_page_header = `<h1>%F's posts:</h1>
|
||||||
%I
|
%I
|
||||||
@ -59,7 +63,8 @@ export const post_page_format = `<h1>%T</h1>
|
|||||||
<i>By <a href="%U">%N</a></i><br/>
|
<i>By <a href="%U">%N</a></i><br/>
|
||||||
<a href="%O">Edit Post</a><br/>
|
<a href="%O">Edit Post</a><br/>
|
||||||
<i>Posted: %D</i><br/>
|
<i>Posted: %D</i><br/>
|
||||||
<i>Edited: %E</i>`
|
<i>Edited: %E</i>
|
||||||
|
%S`
|
||||||
export const timeline_post_format = `<h3>%T</h3>
|
export const timeline_post_format = `<h3>%T</h3>
|
||||||
<p>%C</p>
|
<p>%C</p>
|
||||||
<a href="%L">Permalink</a><br/>
|
<a href="%L">Permalink</a><br/>
|
||||||
@ -71,6 +76,9 @@ export const tag_post_format = `<h3>%T</h3>
|
|||||||
<a href="%L">Permalink</a><br/>
|
<a href="%L">Permalink</a><br/>
|
||||||
<i>By <a href="%U">%N</a></i>
|
<i>By <a href="%U">%N</a></i>
|
||||||
%S`
|
%S`
|
||||||
|
// -------------------------------------
|
||||||
|
export const site_wide_footer = `Site is ran by DeaDvey<br/>
|
||||||
|
%Z`
|
||||||
|
|
||||||
|
|
||||||
/// Custom CSS to be applied to every page
|
/// 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
1
hitcount.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
15
|
Loading…
x
Reference in New Issue
Block a user