view improvements and enforce URL format

merge-requests/208/head
fatchan 5 years ago
parent b113210b47
commit 8c858ba018
  1. 2
      controllers/api.js
  2. 9
      controllers/frontend.js
  3. 9
      views/mixins/post.pug
  4. 13
      views/pages/board.pug
  5. 15
      views/pages/thread.pug

@ -47,7 +47,7 @@ router.get('/api/board/:board/recent/:page', Posts.checkBoard, async (req, res,
}); });
// get a thread // get a thread
router.get('/api/board/:board/thread/:thread', Posts.checkBoard, async (req, res, next) => { router.get('/api/board/:board/thread/:thread([a-f\d]{24})', Posts.checkBoard, async (req, res, next) => {
//get the recently bumped thread & preview posts //get the recently bumped thread & preview posts
let thread; let thread;

@ -38,7 +38,7 @@ router.get('/:board/:page?', Posts.checkBoard, async (req, res, next) => {
}); });
// thread view page // thread view page
router.get('/:board/thread/:thread', Posts.checkBoard, async (req, res, next) => { router.get('/:board/thread/:thread([a-f\\d]{24})', Posts.checkBoard, async (req, res, next) => {
//get the recently bumped thread & preview posts //get the recently bumped thread & preview posts
let thread; let thread;
@ -48,15 +48,18 @@ router.get('/:board/thread/:thread', Posts.checkBoard, async (req, res, next) =>
return next(err); return next(err);
} }
if (!thread) {
return res.status(404).render('404');
}
//render the page //render the page
res.render('thread', { res.render('thread', {
csrf: req.csrfToken(), csrf: req.csrfToken(),
board: req.params.board, board: req.params.board,
threads: [thread] || [] thread: thread
}); });
}); });
module.exports = router; module.exports = router;

@ -0,0 +1,9 @@
mixin post(board, post)
.post-container
if post.thread == null
a(href=`/${board}/thread/${post._id}`) #{post._id}
else
a(href=`/${board}/thread/${post.thread}#${post._id}`) #{post._id}
span , #{post.author}
span , #{post.date}
p #{post.content}

@ -1,20 +1,15 @@
extends ../layout.pug extends ../layout.pug
include ../mixins/post.pug
block head block head
title /#{board}/ title /#{board}/
block content block content
hr
for thread in threads for thread in threads
h1 OP: h1 OP:
div #{thread._id} +post(board, thread)
div #{thread.author}
div #{thread.date}
div #{thread.content}
h1 Replies: h1 Replies:
for post in thread.replies for post in thread.replies
div #{post._id} +post(board, post)
div #{post.author}
div #{post.date}
div #{post.content}
br
hr hr

@ -1,20 +1,13 @@
extends ../layout.pug extends ../layout.pug
include ../mixins/post.pug
block head block head
title /#{board}/ title /#{board}/ - title placeholder
block content block content
for thread in threads
h1 OP: h1 OP:
div #{thread._id} +post(board, thread)
div #{thread.author}
div #{thread.date}
div #{thread.content}
h1 Replies: h1 Replies:
for post in thread.replies for post in thread.replies
div #{post._id} +post(board, post)
div #{post.author}
div #{post.date}
div #{post.content}
br
hr hr

Loading…
Cancel
Save