changes to pages for boards again

merge-requests/208/head
fatchan 5 years ago
parent 17b6a0a47f
commit d956a7fd53
  1. 4
      controllers/pages.js
  2. 1
      db/posts.js
  3. 5
      helpers/paramconverter.js
  4. 2
      helpers/writepagehtml.js
  5. 14
      models/pages/board.js
  6. 2
      server.js
  7. 2
      views/includes/boardheader.pug
  8. 2
      views/includes/navbar.pug
  9. 9
      views/includes/pages.pug
  10. 4
      views/pages/catalog.pug
  11. 2
      views/pages/home.pug
  12. 4
      views/pages/thread.pug
  13. 17
      wipe.js

@ -21,7 +21,7 @@ const express = require('express')
, thread = require(__dirname+'/../models/pages/thread.js');
//homepage with board list
router.get('/', home);
router.get('/index', home);
//login page
router.get('/login', csrf, login);
@ -54,7 +54,7 @@ router.get('/:board/manage', Boards.exists, isLoggedIn, hasPerms, csrf, manage);
router.get('/globalmanage', isLoggedIn, hasPerms, csrf, globalManage);
// board page/recents
router.get('/:board', Boards.exists, paramConverter, board);
router.get('/:board/(:page([2-9]*|index))?', Boards.exists, paramConverter, board);
// thread view page
router.get('/:board/thread/:id(\\d+)', Boards.exists, paramConverter, thread);

@ -10,7 +10,6 @@ module.exports = {
db,
getRecent: async (board, page) => {
// get all thread posts (posts with null thread id)
const threads = await db.find({
'thread': null,

@ -69,6 +69,11 @@ module.exports = (req, res, next) => {
req.body.thread_limit = null;
}
}
if (req.params.page) {
req.params.page = req.params.page === 'index' ? 'index' : +req.params.page;
}
next();
}

@ -10,5 +10,5 @@ const util = require('util')
module.exports = async (htmlName, pugName, pugVars) => {
const html = pug.renderFile(`${pugDirectory}/${pugName}`, pugVars);
return writeFile(`${uploadDirectory}/htmlName`, html);
return writeFile(`${uploadDirectory}html/${htmlName}`, html);
};

@ -1,15 +1,15 @@
'use strict';
const Posts = require(__dirname+'/../../db/posts.js');
const Posts = require(__dirname+'/../../db/posts.js')l
module.exports = async (req, res, next) => {
//get the recently bumped thread & preview posts
const page = req.query.p || 1;
const page = req.params.page === 'index' ? 1 : (req.params.page || 1);
let threads;
let pages;
try {
pages = Math.ceil((await Posts.getPages(req.params.board)) / 10) || 1;
if (page > pages) {
pages = Math.ceil((await Posts.getPages(req.params.board)) / 10)
if (page > pages && pages > 0) {
return next();
}
threads = await Posts.getRecent(req.params.board, page);
@ -17,10 +17,10 @@ module.exports = async (req, res, next) => {
return next(err);
}
//render the page
res.render('board', {
return res.render('board', {
threads: threads || [],
pages,
page,
});
}

@ -9,7 +9,6 @@ const express = require('express')
, path = require('path')
, app = express()
, helmet = require('helmet')
// , csrf = require('csurf')
, bodyParser = require('body-parser')
, cookieParser = require('cookie-parser')
, configs = require(__dirname+'/configs/main.json')
@ -48,7 +47,6 @@ const express = require('express')
// csurf and helmet
app.use(helmet());
// app.use(csrf());
//referer header check
app.use((req, res, next) => {

@ -1,6 +1,6 @@
section.board-header
if board.banners.length > 0
object.board-banner(data=`/banners?board=${board._id}` width='300' height='100')
a.no-decoration(href=`/${board._id}/`)
a.no-decoration(href=`/${board._id}/index`)
h1.board-title /#{board._id}/ - #{board.name}
h4.board-description #{board.description}

@ -2,7 +2,7 @@ nav.navbar
a.nav-item(href='/') Home
a.nav-item.right(href='/logout') Logout
if board
a.nav-item.right(href=`/login?redirect=/${board._id}/`) Login
a.nav-item.right(href=`/login?redirect=/${board._id}/index`) Login
a.nav-item.right(href=`/${board._id}/manage`) Manage
else
a.nav-item.right(href='/login') Login

@ -1,12 +1,15 @@
| Page:
- for(let i = 1; i <= pages; i++)
span
a(href=`/${board._id}/index`) [#{1}]
|
- for(let i = 2; i <= pages; i++)
if i === page
span
a(href=`/${board._id}?p=${i}`) [#{i}]
a(href=`/${board._id}/${i}`) [#{i}]
|
else
span
a(href=`/${board._id}?p=${i}`) #{i}
a(href=`/${board._id}/${i}`) #{i}
|
| |

@ -9,7 +9,7 @@ block content
nav.pages#top
a(href='#bottom') [Bottom]
|
a(href=`/${board._id}/`) [Return]
a(href=`/${board._id}/index`) [Return]
hr(size=1)
if threads.length === 0
p No posts.
@ -20,4 +20,4 @@ block content
nav.pages#bottom
a(href='#top') [Top]
|
a(href=`/${board._id}/`) [Return]
a(href=`/${board._id}/index`) [Return]

@ -14,6 +14,6 @@ block content
th Description
each board in boards
tr.table-row
td: a(href='/'+board._id) /#{board._id}/
td: a(href=`/${board._id}/`) /#{board._id}/
td #{board.name}
td #{board.description}

@ -16,7 +16,7 @@ block content
nav.pages#top
a(href='#bottom') [Bottom]
|
a(href=`/${board._id}/`) [Return]
a(href=`/${board._id}/index`) [Return]
|
a(href=`/${board._id}/catalog`) [Catalog]
hr(size=1)
@ -30,7 +30,7 @@ block content
nav.pages#bottom
a(href='#top') [Top]
|
a(href=`/${board._id}/`) [Return]
a(href=`/${board._id}/index`) [Return]
|
a(href=`/${board._id}/catalog`) [Catalog]
include ../includes/actionfooter.pug

@ -99,19 +99,24 @@ const Mongo = require(__dirname+'/db/db.js')
}
}
});
await readdir('uploads/img/').then(async files => {
await readdir('static/img/').then(async files => {
await Promise.all(files.map(async file => {
unlink(path.join('uploads/img/', file));
unlink(path.join('static/img/', file));
}))
});
await readdir('uploads/captcha/').then(async files => {
await readdir('static/captcha/').then(async files => {
await Promise.all(files.map(async file => {
unlink(path.join('uploads/captcha/', file));
unlink(path.join('static/captcha/', file));
}))
});
await readdir('uploads/banner/').then(async files => {
await readdir('static/banner/').then(async files => {
await Promise.all(files.map(async file => {
unlink(path.join('uploads/banner/', file));
unlink(path.join('static/banner/', file));
}))
});
await readdir('static/html/').then(async files => {
await Promise.all(files.map(async file => {
unlink(path.join('static/html/', file));
}))
});
console.log('creating admin account: admin:changeme');

Loading…
Cancel
Save