hitcount
This commit is contained in:
22
app.js
22
app.js
@@ -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) => {
|
||||
|
Reference in New Issue
Block a user