Added locale (english only at the moment) and modifed the EJS so I think

every string is customisable (via the /locales/selected locale)
This commit is contained in:
2025-08-09 16:57:31 +01:00
parent 8418318d80
commit 6fc1f85e18
17 changed files with 187 additions and 80 deletions

38
locales/en.json Normal file
View File

@@ -0,0 +1,38 @@
{
"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>"
}

View File

@@ -40,6 +40,15 @@ catch (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)
}
// https://showdownjs.com/docs/available-options
let converter = new showdown.Converter({
simpleLineBreaks: true, // Parse line breaks as <br/> in paragraphs (GitHub-style behavior).
@@ -64,7 +73,7 @@ app.set('views', '../views')
app.get("/rss", (req,res) => {
if (config.rss == false) {
res.render("partials/message", {
message: config.string.rss_disabled,
message: locale.rss_disabled,
config: config,
})
}
@@ -84,7 +93,7 @@ app.get("/user/:username/rss", (req,res) => {
const userID = func.get_userID(username);
if (config.rss == false) {
res.render("partials/message", {
message: config.string.rss_disabled,
message: locale.rss_disabled,
config: config,
})
}
@@ -103,7 +112,7 @@ app.get("/user/:username/rss", (req,res) => {
app.get("/atom", (req,res) => {
if (config.atom == false) {
res.render("partials/message", {
message: config.string.atom_disabled,
message: locale.atom_disabled,
config: config,
})
}
@@ -124,7 +133,7 @@ app.get("/user/:username/atom", (req,res) => {
const userID = func.get_userID(username);
if (config.atom == false) {
res.render("partials/message", {
message: config.string.atom_disabled,
message: locale.atom_disabled,
config: config,
})
}
@@ -183,6 +192,7 @@ app.get("/", (req,res) => {
res.render("pages/timeline",
{
config,
locale,
posts,
users,
comments: comments.comments,
@@ -200,8 +210,9 @@ app.get("/user/:username", (req, res) => {
console.log(users[userID].prettyname)
res.render("pages/user",
{
config: config,
posts: posts,
config,
locale,
posts,
user: users[userID],
userID: userID,
comments: comments.comments,
@@ -216,7 +227,7 @@ app.get("/post/:post_index", (req, res) => {
const postID = req.params.post_index
if (posts[postID]["deleted"] == true) {
res.render("partials/message", {
message: config.string.post_doesnt_exist,
message: locale.post_doesnt_exist,
config,
})
}
@@ -224,6 +235,7 @@ app.get("/post/:post_index", (req, res) => {
res.render("pages/post",
{
config,
locale,
post: posts[postID],
postID: postID,
user: users[posts[postID].userID],
@@ -244,10 +256,11 @@ app.get("/tag/:tag", (req,res) => {
const tag = req.params.tag
res.render("pages/tag",
{
config: config,
tag: tag,
posts: posts,
users: users,
config,
locale,
tag,
posts,
users,
comments: comments.comments,
fromUnixTime: fromUnixTime,
format: format,
@@ -262,13 +275,14 @@ app.get("/comment/:commentID", (req,res) => {
if (comment == -1) {
res.render("partials/message", {
config,
message: config.string.comment_doesnt_exist,
message: locale.comment_doesnt_exist,
})
}
else {
res.render("pages/comment",
{
config: config,
locale,
post: posts[comment["id"]],
users,
comment,
@@ -285,7 +299,8 @@ app.get("/comment/:commentID", (req,res) => {
///////////////////// Form pages ////////////////////////////
app.get(config.new_post_url, (req,res) => {
res.render("forms/new_post", {
config
config,
locale,
});
}); // /post
app.get(config.signup_url, (req,res) => {
@@ -293,13 +308,14 @@ app.get(config.signup_url, (req,res) => {
if (config.allow_signup == true) {
// Send the page for signing up to the server
res.render("forms/signup", {
config
config,
locale,
});
}
// if the server does not allow signup
else if (config.allow_signup == false) {
res.render("partials/message", {
message: config.string.signups_unavailable,
message: locale.signups_unavailable,
config,
})
}
@@ -311,7 +327,12 @@ app.get(config.signup_url, (req,res) => {
}); // /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, user: users[userID], userID });
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
@@ -319,6 +340,7 @@ app.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
const user = users[post['userID']]
res.render("forms/edit_post", {
config,
locale,
post,
post_id,
user,
@@ -355,7 +377,7 @@ app.post("/submit_post", (req,res) => {
if (func.get_userID(username) == -1) {
res.render("partials/message", {
message: config.string.user_doesnt_exit,
message: locale.user_doesnt_exit,
config,
})
}
@@ -378,7 +400,7 @@ app.post("/submit_post", (req,res) => {
}
else {
res.render("partials/message", {
message: config.string.incorrect_password,
message: locale.incorrect_password,
config,
})
}
@@ -407,14 +429,14 @@ app.post("/submit_signup", (req,res) => {
// if the user does exist then
else {
res.render("partials/message", {
message: config.string.user_exists,
message: locale.user_exists,
config,
})
}
}
else if (config.allow_signup == false) {
res.render("partials/message", {
message: config.string.signups_unavailable,
message: locale.signups_unavailable,
config,
})
}
@@ -457,7 +479,7 @@ app.post("/submit_edit_user", (req,res) => {
}
else { // password does not match
res.render("partials/message", {
message: config.string.incorrect_password,
message: locale.incorrect_password,
config
}
)
@@ -465,7 +487,7 @@ app.post("/submit_edit_user", (req,res) => {
}
else {
res.render("partials/message", {
message: config.string.user_doesnt_exist,
message: locale.user_doesnt_exist,
config,
})
}
@@ -498,7 +520,7 @@ app.post("/submit_edit_post", (req,res) => {
}
else {
res.render("partials/message", {
message: config.string.incorrect_password,
message: locale.incorrect_password,
config,
})
}

View File

@@ -6,10 +6,16 @@
<body>
<form action="/submit_edit_user" method="POST">
<input name="userID" type="hidden" value="<%= userID %>">
<input placeholder="<%= user.prettyname %>'s password" type="password" required id="password" name="password"><br/>
<input placeholder="Pretty Name" name="prettyname" value="<%= user.prettyname %>"><br/>
<textarea placeholder="Description" name="description"><%= user.description %></textarea><br/>
<label><%- config.string.delete_account_confirmation %>: </label><input type="checkbox" name="agreement"><br/>
<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>

View File

@@ -7,13 +7,21 @@
<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 %>">
<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><%= 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/>
<small>* Markdown supported</small>
</form>
</body>
</html>

View File

@@ -5,12 +5,21 @@
</head>
<body>
<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/>
<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/>
<small>* Markdown supported</small>
</body>
</form></html>

View File

@@ -5,11 +5,19 @@
</head>
<body>
<form action="/submit_signup" method="POST">
<input placeholder="username" required name="username"><br/>
<input placeholder="prettyname" required name="prettyname"><br/>
<input placeholder="password" type="password" required id="password" name="password"><br/>
<textarea placeholder="description (social links, what you do etc), supports markdown" id="description" name="description"></textarea><br/>
<label><%- config.string.signup_agreement %>: </label><input type="checkbox" name="agreement" required><br/>
<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>

View File

@@ -1 +1,5 @@
<a href="/">Home Page</a><br/>
<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 %>

View File

@@ -1,4 +1,4 @@
<h1>
Post's tagged "<%- tag %>":
<%= locale.posts_tagged %>: "<%- tag %>"
</h1>
<%- config.seperator %>

View File

@@ -4,11 +4,17 @@
<h2>
<%- config.site_description %>
</h2>
<a href="/rss">RSS Feed</a><br/>
<a href="/atom">ATOM Feed</a><br/>
<a href="<%= config.new_post_url %>">New post</a><br/>
<a href="<%= config.signup_url %>">Sign Up</a><br/>
<% 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) { %>
Hitcount: <%= hitcount %>
<%= locale.hitcount %>: <%= hitcount %>
<% } %>
<%- config.seperator %>

View File

@@ -1,8 +1,8 @@
<h1>
<%= user.prettyname %>'s posts
<%= user.prettyname %>
</h1>
<p><%- converter.makeHtml(user.description) %></p>
<a href="<%= config.edit_account_base_url %>/<%= userID %>">edit account</a><br/>
<a href="/user/<%= user.username %>/rss">RSS</a><br/>
<a href="/user/<%= user.username %>/atom">ATOM</a>
<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 %>

View File

@@ -10,11 +10,13 @@
</div>
<div id="posts">
<% for (let index = posts.length - 1; index >= 0; index--) { %>
<% posts[index].tags.forEach((current_tag, tag_index) => { %>
<% if (current_tag == tag) { %>
<%- include('../posts/tag', {post: posts[index], postID: index}); %>
<% } %>
<% }) %>
<% if ( posts[index].deleted != true) { %>
<% posts[index].tags.forEach((current_tag, tag_index) => { %>
<% if (current_tag == tag) { %>
<%- include('../posts/tag', {post: posts[index], postID: index}); %>
<% } %>
<% }) %>
<% } %>
<% } %>
</div>
<footer>

View File

@@ -9,6 +9,7 @@
<%- 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/>

View File

@@ -1,2 +1,2 @@
Site is ran by deadvey<br/>
<%- config.string.attribution %>
<%- locale.attribution %>

View File

@@ -3,21 +3,21 @@
</h1>
<%- converter.makeHtml(post.content) %><br/>
<i>
By <a href="/user/<%= user.username %>"><%= user.username %></a><br/>
<%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/>
</i>
<%- func.hyperlink_tags(post.tags) %><br/>
<a href="<%= config.edit_post_base_url %>/<%= postID %>">Edit</a><br/>
<i>Published: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
<i>Last Modified: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
<a href="<%= config.edit_post_base_url %>/<%= postID %>"><%= locale.edit_post %></a><br/>
<i><%= locale.published %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
<i><%= locale.last_modified %>: <%= func.unix_time_to_date_format(post.pubdate) %></i><br/>
<%- config.seperator %>
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= postID %>">
<input placeholder="username" name="name"><br/>
<textarea placeholder="comment" name="content"></textarea><br/>
<button type="submit">Submit</button>
<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>
<% comments.forEach((comment, postID) => { %>

View File

@@ -2,15 +2,16 @@
<%= post.title %>
</h3>
<%- converter.makeHtml(post.content) %><br/>
<a href="/post/<%- postID %>">Permalink</a><br/>
<a href="/post/<%- postID %>"><%= locale.permalink %></a><br/>
<%- func.hyperlink_tags(post.tags) %>
<br/>
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= postID %>">
<input placeholder="username" name="name"><br/>
<textarea placeholder="comment" name="content"></textarea><br/>
<button type="submit">Submit</button>
<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>
<% comments[postID].forEach((comment) => { %>

View File

@@ -2,17 +2,18 @@
<%= post.title %>
</h3>
<%- converter.makeHtml(post.content) %><br/>
<a href="/post/<%- index %>">Permalink</a><br/>
<a href="/post/<%- index %>"><%= locale.permalink %></a><br/>
<i>
By <a href="/user/<%= user.username %>"><%= user.username %></a><br/>
<%= locale.written_by %> <a href="/user/<%= user.username %>"><%= user.username %></a><br/>
</i>
<br/>
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= index %>">
<input placeholder="username" name="name"><br/>
<textarea placeholder="comment" name="content"></textarea><br/>
<button type="submit">Submit</button>
<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>
<% comments[index].forEach((comment, index) => { %>

View File

@@ -2,14 +2,15 @@
<%= post.title %>
</h3>
<%- converter.makeHtml(post.content) %><br/>
<a href="/post/<%- index %>">Permalink</a><br/>
<a href="/post/<%- index %>"><%= locale.permalink %></a><br/>
<br/>
<!-- Comment form -->
<form method="POST" action="/submit_comment">
<input type="hidden" name="post_index" value="<%= index %>">
<input placeholder="username" name="name"><br/>
<textarea placeholder="comment" name="content"></textarea><br/>
<button type="submit">Submit</button>
<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>
<% comments[index].forEach((comment, index) => { %>