Automatically removes leading and trailing spaces from tags because tags
are often entered with a space after each comma. This uses .trim() in func.render_tags() to remove when rendering as well as .map(str => str.trim()) when a post or post edit is submitted so they are also stored without spaces.
This commit is contained in:
@@ -44,7 +44,7 @@ export function render_tags(tags) {
|
||||
}
|
||||
else {
|
||||
for (let tag_index = 0; tag_index < tags.length; tag_index++) { // Loop over each tag
|
||||
string += `<a href="/tag/${tags[tag_index]}">${tags[tag_index]}</a>` // Adds the tag to the string as a HTML href
|
||||
string += `<a href="/tag/${tags[tag_index].trim()}">${tags[tag_index].trim()}</a>` // Adds the tag to the string as a HTML href
|
||||
if (tag_index < tags.length - 1) { // If there are more tags, then insert a comma
|
||||
string += ", ";
|
||||
}
|
||||
|
@@ -360,7 +360,7 @@ app.post("/submit_post", (req,res) => {
|
||||
const username = func.escape_input(req.body.username)
|
||||
const title = func.escape_input(req.body.title)
|
||||
const content = req.body.content
|
||||
const tags = func.escape_input(req.body.tags).split(',');
|
||||
const tags = func.escape_input(req.body.tags).split(',').map(str => str.trim());
|
||||
const unix_timestamp = getUnixTime(new Date())
|
||||
|
||||
if (func.get_userID(username) == -1) {
|
||||
@@ -486,7 +486,7 @@ app.post("/submit_edit_post", (req,res) => {
|
||||
const userID = req.body.userID
|
||||
const title = func.escape_input(req.body.title)
|
||||
const content = req.body.content
|
||||
const tags = func.escape_input(req.body.tags).split(",")
|
||||
const tags = func.escape_input(req.body.tags).split(",").map(str => str.trim());
|
||||
const delete_bool = req.body.delete
|
||||
const unix_timestamp = getUnixTime(new Date())
|
||||
console.log(users[userID]['prettyname'], "is editting the post titled:", title);
|
||||
|
Reference in New Issue
Block a user