data.getdata() is fully implemented

I think it all works now...

Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
2025-09-24 19:31:32 +01:00
parent e597fd78f7
commit 22a7983737
10 changed files with 28 additions and 16 deletions

View File

@@ -1 +1 @@
{"hitcount":27} {"hitcount":37}

View File

@@ -38,19 +38,19 @@ router.get(`${config.edit_account_base_url}/:user_id`, (req,res) => {
res.render("forms/edit_account", { res.render("forms/edit_account", {
config, config,
locale, locale,
user: users[userID], user: data.getdata('users', userID),
userID userID
}); });
}); // /delete_account }); // /delete_account
router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => { router.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
const post_id = req.params.post_id const postID = req.params.post_id
const post = posts[post_id] const post = data.getdata('posts', postID)
const user = users[post['userID']] const user = data.getdata('users', post.userID)
res.render("forms/edit_post", { res.render("forms/edit_post", {
config, config,
locale, locale,
post, post,
post_id, postID,
user, user,
}); });
}); // /edit/:post_id }); // /edit/:post_id

View File

@@ -9,9 +9,9 @@ const router = express.Router();
router.get("/index/pages", (req,res) => { router.get("/index/pages", (req,res) => {
res.render("indexes/all_pages", { res.render("indexes/all_pages", {
config, config,
posts, posts: data.getdata('posts'),
users, users: data.getdata('users'),
comments: comments.comments, comments: data.getdata('comments'),
}); });
}); // /index/posts }); // /index/posts
router.get("/index/posts", (req,res) => { router.get("/index/posts", (req,res) => {

View File

@@ -7,6 +7,8 @@ const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date util
const router = express.Router(); const router = express.Router();
///////////////////// Standard Pages ////////////////////// ///////////////////// Standard Pages //////////////////////
// Timeline
router.get("/", (req,res) => { router.get("/", (req,res) => {
// Increment the hitcount // Increment the hitcount
if (config.enable_hitcount) { if (config.enable_hitcount) {
@@ -27,6 +29,8 @@ router.get("/", (req,res) => {
func, func,
}) })
}); // / }); // /
// Users
router.get("/user/:username", (req, res) => { router.get("/user/:username", (req, res) => {
const userID = func.get_userID(req.params.username) const userID = func.get_userID(req.params.username)
let user = data.getdata('users', userID) let user = data.getdata('users', userID)
@@ -53,6 +57,8 @@ router.get("/user/:username", (req, res) => {
}) })
} }
}); // /user/:username }); // /user/:username
// Posts
router.get("/post/:post_index", (req, res) => { router.get("/post/:post_index", (req, res) => {
const postID = req.params.post_index const postID = req.params.post_index
let post = data.getdata('posts', postID) let post = data.getdata('posts', postID)
@@ -85,6 +91,7 @@ router.get("/post/:post_index", (req, res) => {
}); // /post/:post_index }); // /post/:post_index
// Tags
router.get("/tag/:tag", (req,res) => { router.get("/tag/:tag", (req,res) => {
const tag = req.params.tag const tag = req.params.tag
res.render("pages/tag", res.render("pages/tag",
@@ -101,6 +108,9 @@ router.get("/tag/:tag", (req,res) => {
func, func,
}) })
}); // /tag/:tag }); // /tag/:tag
// Comments
router.get("/comment/:postID-:commentID", (req,res) => { router.get("/comment/:postID-:commentID", (req,res) => {
const commentID = req.params.commentID; const commentID = req.params.commentID;
const postID = req.params.postID; const postID = req.params.postID;

View File

@@ -3,6 +3,8 @@ const config = require('../../config')
const data = require('../data') const data = require('../data')
const func = require('../functions') const func = require('../functions')
const { fromUnixTime, format, getUnixTime } = require("date-fns") // A date utility library
const router = express.Router(); const router = express.Router();
////////////////////// SYNDICATION //////////////////////// ////////////////////// SYNDICATION ////////////////////////

View File

@@ -6,7 +6,7 @@
<body> <body>
<form action="/submit_edit_post" method="POST" onsubmit="sha512password()"> <form action="/submit_edit_post" method="POST" onsubmit="sha512password()">
<input name="userID" type="hidden" value="<%= post['userID'] %>"> <input name="userID" type="hidden" value="<%= post['userID'] %>">
<input name="postID" type="hidden" value="<%= post_id %>"> <input name="postID" type="hidden" value="<%= postID %>">
<label><%= locale.password %>:</label><br/> <label><%= locale.password %>:</label><br/>
<input type="password" required id="password" name="password"><br/><br/> <input type="password" required id="password" name="password"><br/><br/>

View File

@@ -1,7 +1,7 @@
<h1> <h1>
<%= user.prettyname %> <%= user.prettyname %>
</h1> </h1>
<p><%# func.render_md(user.description) %></p> <p><%- func.render_md(user.description) %></p>
<a href="<%= config.edit_account_base_url %>/<%= userID %>"><%= locale.edit_account %></a><br/> <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 %>/rss"><%= locale.rss_feed %></a><br/>
<a href="/user/<%= user.username %>/atom"><%= locale.atom_feed %></a> <a href="/user/<%= user.username %>/atom"><%= locale.atom_feed %></a>

View File

@@ -21,7 +21,7 @@
Comments:<br/> Comments:<br/>
<% for (let postID = 0; postID < comments.length; postID++) { %> <% for (let postID = 0; postID < comments.length; postID++) { %>
<% for (let comment_index = 0; comment_index < comments[postID].length; comment_index++) { %> <% for (let comment_index = 0; comment_index < comments[postID].length; comment_index++) { %>
<a href="/comment/<%= comments[postID][comment_index]["id"] %>"><%= comments[postID][comment_index]["id"] %></a><br/> <a href="/comment/<%= postID %>-<%= comment_index %>"><%= postID %>-<%= comment_index %></a><br/>
<% }; %> <% }; %>
<% }; %> <% }; %>
Users:<br/> Users:<br/>
@@ -33,13 +33,13 @@
Edit Posts:<br/> Edit Posts:<br/>
<% for (let postID = 0; postID < posts.length; postID++) { %> <% for (let postID = 0; postID < posts.length; postID++) { %>
<% if (posts[postID]["deleted"] != true) { %> <% if (posts[postID]["deleted"] != true) { %>
<a href="/<%= config.edit_post_base_url %>/<%= postID %>">Edit <%= posts[postID]["title"] %></a><br/> <a href="<%= config.edit_post_base_url %>/<%= postID %>">Edit <%= posts[postID]["title"] %></a><br/>
<% }; %> <% }; %>
<% }; %> <% }; %>
Edit Users:<br/> Edit Users:<br/>
<% for (let userID = 0; userID < users.length; userID++) { %> <% for (let userID = 0; userID < users.length; userID++) { %>
<% if (users[userID]["deleted"] != true) { %> <% if (users[userID]["deleted"] != true) { %>
<a href="/<%= config.edit_account_base_url %>/<%= users[userID]["username"] %>">Edit <%= users[userID]["username"] %></a><br/> <a href="<%= config.edit_account_base_url %>/<%= users[userID]["username"] %>">Edit <%= users[userID]["username"] %></a><br/>
<% }; %> <% }; %>
<% }; %> <% }; %>
<!-- TODO add tags --> <!-- TODO add tags -->

View File

@@ -6,7 +6,7 @@
<body> <body>
<% for (let postID = 0; postID < comments.length; postID++) { %> <% for (let postID = 0; postID < comments.length; postID++) { %>
<% for (let comment_index = 0; comment_index < comments[postID].length; comment_index++) { %> <% for (let comment_index = 0; comment_index < comments[postID].length; comment_index++) { %>
<a href="/comment/<%= comments[postID][comment_index]["id"] %>"><%= comments[postID][comment_index]["id"] %></a><br/> <a href="/comment/<%= postID %>-<%= comment_index %>"><%= postID %>-<%= comment_index %></a><br/>
<% }; %> <% }; %>
<% }; %> <% }; %>
</body> </body>

View File

@@ -13,7 +13,7 @@
<% if ( posts[index].deleted != true) { %> <% if ( posts[index].deleted != true) { %>
<% posts[index].tags.forEach((current_tag, tag_index) => { %> <% posts[index].tags.forEach((current_tag, tag_index) => { %>
<% if (current_tag == tag) { %> <% if (current_tag == tag) { %>
<%- include('../posts/tag', {post: posts[index], user: users[posts[index].userID], comments: comments[index]}); %> <%- include('../posts/tag', {post: posts[index], postID: index, user: users[posts[index].userID], comments: comments[index]}); %>
<% } %> <% } %>
<% }) %> <% }) %>
<% } %> <% } %>