add a board list with pages that also shows webring boards

merge-requests/208/head
fatchan 5 years ago
parent 339a743b1b
commit 8d82cad62d
  1. 11
      controllers/pages.js
  2. 14
      db/boards.js
  3. 8
      gulp/res/css/style.css
  4. 2
      gulp/res/js/post.js
  5. 4
      helpers/paramconverter.js
  6. 7
      helpers/tasks.js
  7. 2
      models/pages/board.js
  8. 40
      models/pages/boardlist.js
  9. 1
      server.js
  10. 9
      views/includes/boardlistpages.pug
  11. 10
      views/includes/boardpages.pug
  12. 8
      views/includes/boardtable.pug
  13. 10
      views/includes/pages.pug
  14. 10
      views/mixins/globalmanagenav.pug
  15. 8
      views/mixins/managenav.pug
  16. 2
      views/mixins/post.pug
  17. 36
      views/pages/boardlist.pug

@ -29,7 +29,8 @@ const express = require('express')
, captcha = require(__dirname+'/../models/pages/captcha.js')
, thread = require(__dirname+'/../models/pages/thread.js')
, modlog = require(__dirname+'/../models/pages/modlog.js')
, modloglist = require(__dirname+'/../models/pages/modloglist.js');
, modloglist = require(__dirname+'/../models/pages/modloglist.js')
, boardlist = require(__dirname+'/../models/pages/boardlist.js');
//homepage
router.get('/index.html', home);
@ -37,6 +38,9 @@ router.get('/index.html', home);
//news page
router.get('/news.html', news);
//board list
router.get('/boards.html', boardlist);
//board pages
router.get('/:board/:page(1[0-9]*|[2-9]*|index).html', Boards.exists, paramConverter, board); //index
router.get('/:board/thread/:id(\\d+).html', Boards.exists, paramConverter, Posts.exists, thread); //thread view
@ -52,6 +56,11 @@ router.get('/:board/manage/reports.html', sessionRefresh, isLoggedIn, Boards.exi
router.get('/:board/manage/bans.html', sessionRefresh, isLoggedIn, Boards.exists, calcPerms, hasPerms(3), csrf, manageBans);
router.get('/:board/manage/settings.html', sessionRefresh, isLoggedIn, Boards.exists, calcPerms, hasPerms(2), csrf, manageSettings);
router.get('/:board/manage/banners.html', sessionRefresh, isLoggedIn, Boards.exists, calcPerms, hasPerms(2), csrf, manageBanners);
/*
todo: dynamic mod pages with no captcha required for mod forms
router.get('/:board/manage/:page(1[0-9]*|[2-9]*|index).html', sessionRefresh, isLoggedIn, Boards.exists, paramConverter, calcPerms, hasPerms(2), csrf, manageBoard);
router.get('/:board/manage/thread/:id(\\d+).html', sessionRefresh, isLoggedIn, Boards.exists, paramConverter, calcPerms, hasPerms(2), csrf, manageThread);
*/
//global manage pages
router.get('/globalmanage/reports.html', sessionRefresh, isLoggedIn, calcPerms, hasPerms(1), csrf, globalManageReports);

@ -48,10 +48,6 @@ module.exports = {
});
},
find: () => {
return db.find({}).toArray();
},
insertOne: (data) => {
cache.del(`board_${data._id}`); //removing cached no_exist
return db.insertOne(data);
@ -104,11 +100,9 @@ module.exports = {
);
},
boardSort: (skip=0, limit=20) => {
boardSort: (skip=0, limit=50) => {
return db.find({
'settings.unlisted': {
'$ne': true
}
'settings.unlisted': false,
}, {
'projection': {
'_id': 1,
@ -126,6 +120,10 @@ module.exports = {
}).skip(skip).limit(limit).toArray();
},
count: (showUnlisted=false) => {
return db.countDocuments(showUnlisted ? {} : { 'settings.unlisted': false });
},
totalStats: () => {
return db.aggregate([
{

@ -754,14 +754,6 @@ hr + .thread {
margin-top: -5px;
}
.webringtable th {
position: sticky; top: 0;
}
.boardtable.webringtable {
border: none;
}
.scrolltable {
max-height: 160px;
overflow-y: auto;

@ -56,7 +56,7 @@ if (post.capcode) {
pug_html = pug_html + "\u003Cspan class=\"post-capcode\"\u003E" + (pug_escape(null == (pug_interp = post.capcode) ? "" : pug_interp)) + "\u003C\u002Fspan\u003E ";
}
const postDate = new Date(post.date)
pug_html = pug_html + "\u003Ctime" + (" class=\"post-date\""+pug_attr("datetime", postDate.toISOString(), true, false)) + "\u003E" + (pug_escape(null == (pug_interp = postDate.toLocaleString(undefined, {hour12:false})) ? "" : pug_interp)) + "\u003C\u002Ftime\u003E ";
pug_html = pug_html + "\u003Ctime" + (" class=\"post-date\""+pug_attr("datetime", postDate.toISOString(), true, false)) + "\u003E" + (pug_escape(null == (pug_interp = postDate.toLocaleString("en-US", { hour12:false, timeZone: "America/New_York" })) ? "" : pug_interp)) + "\u003C\u002Ftime\u003E ";
if (post.userId) {
pug_html = pug_html + "\u003Cspan" + (" class=\"user-id\""+pug_attr("style", pug_style(`background-color: #${post.userId}`), true, false)) + "\u003E" + (pug_escape(null == (pug_interp = post.userId) ? "" : pug_interp)) + "\u003C\u002Fspan\u003E ";
}

@ -110,10 +110,6 @@ module.exports = (req, res, next) => {
res.locals.date = date;
}
}
//board page
if (req.params.page) {
req.params.page = req.params.page === 'index' ? 'index' : +req.params.page;
}
next();

@ -171,19 +171,14 @@ module.exports = {
buildHomepage: async () => {
const label = '/index.html';
const start = process.hrtime();
let [ totalStats, boards, webringBoards, fileStats ] = await Promise.all([
let [ totalStats, boards, fileStats ] = await Promise.all([
Boards.totalStats(), //overall total posts ever made
Boards.boardSort(0, 20), //top 20 boards sorted by users, pph, total posts
enableWebring ? cache.get('webring:boards') : null, //webring boards if enabled
Files.activeContent() //size ans number of files
]);
if (enableWebring && webringBoards) { //sort webring boards
webringBoards = webringBoards.sort((a, b) => { return b.uniqueUsers - a.uniqueUsers });
}
const html = render('index.html', 'home.pug', {
totalStats,
boards,
webringBoards,
fileStats,
});
const end = process.hrtime(start);

@ -5,7 +5,7 @@ const Posts = require(__dirname+'/../../db/posts.js')
module.exports = async (req, res, next) => {
const page = req.params.page === 'index' ? 1 : req.params.page;
const page = req.params.page === 'index' ? 1 : Number(req.params.page);
let html;
try {
const maxPage = Math.min(Math.ceil((await Posts.getPages(req.params.board)) / 10), Math.ceil(res.locals.board.settings.threadLimit/10)) || 1;

@ -0,0 +1,40 @@
'use strict';
const cache = require(__dirname+'/../../redis.js')
, { enableWebring } = require(__dirname+'/../../configs/main.json')
, { Boards } = require(__dirname+'/../../db/')
, limit = 20;
module.exports = async (req, res, next) => {
let page;
if (req.query.page && !isNaN(parseInt(req.query.page))) {
page = parseInt(req.query.page) || 1; //or 1 prevent 0 page
} else {
page = 1;
}
const offset = (page-1) * limit;
let boards, webringBoards, localPages, webringPages;
try {
[ boards, webringBoards, localPages ] = await Promise.all([
Boards.boardSort(offset, limit),
enableWebring ? cache.get('webring:boards') : null,
Boards.count(),
]);
} catch (err) {
return next(err);
}
localPages = Math.ceil(localPages / limit);
if (enableWebring && webringBoards) { //sort webring boards
webringPages = Math.ceil(webringBoards.length / limit);
webringBoards = webringBoards.sort((a, b) => { return b.uniqueUsers - a.uniqueUsers }).splice(offset, limit);
}
const maxPage = Math.max(localPages, webringPages);
return res.render('boardlist', {
boards,
webringBoards,
page,
maxPage
});
}

@ -77,6 +77,7 @@ const express = require('express')
//default settings
app.locals.defaultTheme = configs.boardDefaults.theme;
app.locals.globalLimits = configs.globalLimits;
app.locals.meta = configs.meta;
app.locals.themes = themes;
// routes

@ -0,0 +1,9 @@
| Page:
if maxPage === 0
a.bold(href='?page=1') [1]
- for(let i = 1; i <= maxPage; i++)
if page === i
a.bold(href=`?page=${i}`) [#{i}]
else
a(href=`?page=${i}`) [#{i}]
|

@ -0,0 +1,10 @@
| Page:
if maxPage === 0
a.bold(href=`index.html`) [1]
- for(let i = 1; i <= maxPage; i++)
if page === i
a.bold(href=`${i === 1 ? 'index' : i}.html`) [#{i}]
else
a(href=`${i === 1 ? 'index' : i}.html`) [#{i}]
|
| |

@ -0,0 +1,8 @@
.table-container.flex-center.mv-10.text-center
table.boardtable
tr
th Board
th Description
th.help(title='Posts in the last hour') PPH
th.help(title='Unique posters in the last 24h') Users
th Posts

@ -1,10 +0,0 @@
| Page:
if maxPage === 0
a.bold(href=`/${board._id}/index.html`) [1]
- for(let i = 1; i <= maxPage; i++)
if page === i
a.bold(href=`/${board._id}/${i === 1 ? 'index' : i}.html`) [#{i}]
else
a(href=`/${board._id}/${i === 1 ? 'index' : i}.html`) #{i}
|
| |

@ -1,13 +1,13 @@
mixin globalmanagenav(selected)
nav.pages
a(href=`/globalmanage/reports.html` class=(selected === 'reports' ? 'bold' : '')) [Reports]
a(href='reports.html' class=(selected === 'reports' ? 'bold' : '')) [Reports]
|
a(href=`/globalmanage/bans.html` class=(selected === 'bans' ? 'bold' : '')) [Bans]
a(href='bans.html' class=(selected === 'bans' ? 'bold' : '')) [Bans]
|
a(href=`/globalmanage/recent.html` class=(selected === 'recent' ? 'bold' : '')) [Recent]
a(href='recent.html' class=(selected === 'recent' ? 'bold' : '')) [Recent]
if permLevel === 0
|
a(href=`/globalmanage/accounts.html` class=(selected === 'accounts' ? 'bold' : '')) [Accounts]
a(href='accounts.html' class=(selected === 'accounts' ? 'bold' : '')) [Accounts]
|
a(href=`/globalmanage/news.html` class=(selected === 'news' ? 'bold' : '')) [News]
a(href='news.html' class=(selected === 'news' ? 'bold' : '')) [News]

@ -1,10 +1,10 @@
mixin managenav(selected)
nav.pages
a(href=`/${board._id}/manage/reports.html` class=(selected === 'reports' ? 'bold' : '')) [Reports]
a(href='reports.html' class=(selected === 'reports' ? 'bold' : '')) [Reports]
|
a(href=`/${board._id}/manage/bans.html` class=(selected === 'bans' ? 'bold' : '')) [Bans]
a(href='bans.html' class=(selected === 'bans' ? 'bold' : '')) [Bans]
|
if permLevel < 3
a(href=`/${board._id}/manage/settings.html` class=(selected === 'settings' ? 'bold' : '')) [Settings]
a(href='settings.html' class=(selected === 'settings' ? 'bold' : '')) [Settings]
|
a(href=`/${board._id}/manage/banners.html` class=(selected === 'banners' ? 'bold' : '')) [Banners]
a(href='banners.html' class=(selected === 'banners' ? 'bold' : '')) [Banners]

@ -31,7 +31,7 @@ mixin post(post, truncate, manage=false, globalmanage=false, ban=false)
span.post-capcode #{post.capcode}
|
- const postDate = new Date(post.date)
time.post-date(datetime=postDate.toISOString()) #{postDate.toLocaleString(undefined, {hour12:false})}
time.post-date(datetime=postDate.toISOString()) #{postDate.toLocaleString("en-US", { hour12:false, timeZone: "America/New_York" })}
|
if post.userId
span.user-id(style=`background-color: #${post.userId}`) #{post.userId}

@ -0,0 +1,36 @@
extends ../layout.pug
block head
script(src='/js/theme.js')
title #{meta.siteName}
block content
h1.board-title Board List
if boards && boards.length > 0
h4.board-description Local Boards
include ../includes/boardtable.pug
each board in boards
tr
td
if board.settings.sfw
span.help(title='Safe for work') &#128188;
a(href=`/${board._id}/index.html`) /#{board._id}/ - #{board.settings.name}
td #{board.settings.description}
td #{board.pph}
td #{board.ips}
td #{board.sequence_value-1}
if webringBoards && webringBoards.length > 0
h4.board-description Webring Boards
include ../includes/boardtable.pug
each board in webringBoards
tr
td
if !board.nsfw
span.help(title='Safe for work') &#128188;
a(href=board.path) #{board.siteName} /#{board.uri}/ - #{board.title}
td #{board.subtitle || '-'}
td #{board.postsPerHour || '-'}
td #{board.uniqueUsers || '-'}
td #{board.totalPosts || '-'}
nav.pages.text-center
include ../includes/boardlistpages.pug
Loading…
Cancel
Save