optional recent news on homepage and config for max number to show

merge-requests/208/head
fatchan 4 years ago
parent db1982ac31
commit 5606b2470f
  1. 3
      configs/main.js.example
  2. 6
      db/news.js
  3. 4
      gulp/res/css/style.css
  4. 8
      helpers/tasks.js
  5. 16
      views/pages/home.pug

@ -130,6 +130,9 @@ module.exports = {
//how many replies a thread needs to not get removed by early404
early404Replies: 5,
//how many of the most recent newsposts to show on the homepage
maxRecentNews: 3,
/* filter filenames on posts and banners
false=no filtering
true=allow only A-Za-z0-9_-

@ -8,10 +8,12 @@ module.exports = {
db,
find: () => {
find: (limit=0) => {
return db.find({}).sort({
'_id': -1
}).toArray();
})
.limit(limit)
.toArray();
},
insertOne: (news) => {

@ -1052,6 +1052,10 @@ table, .boardtable {
display: none;
}
table.newstable td:nth-child(2), table.newstable th:nth-child(2) {
display: none;
}
.modal {
top: 5px;
max-height: calc(100% - 10px);

@ -5,7 +5,7 @@ const Mongo = require(__dirname+'/../db/db.js')
, timeUtils = require(__dirname+'/timeutils.js')
, uploadDirectory = require(__dirname+'/files/uploadDirectory.js')
, { remove } = require('fs-extra')
, { debugLogs, pruneModlogs, pruneAfterDays, enableWebring } = require(__dirname+'/../configs/main.js')
, { debugLogs, pruneModlogs, pruneAfterDays, enableWebring, maxRecentNews } = require(__dirname+'/../configs/main.js')
, { Stats, Posts, Files, Boards, News, Modlogs } = require(__dirname+'/../db/')
, render = require(__dirname+'/render.js')
, timeDiffString = require(__dirname+'/timediffstring.js');
@ -195,15 +195,17 @@ module.exports = {
buildHomepage: async () => {
const label = '/index.html';
const start = process.hrtime();
let [ totalStats, boards, fileStats ] = await Promise.all([
let [ totalStats, boards, fileStats, recentNews ] = await Promise.all([
Boards.totalStats(), //overall total posts ever made
Boards.boardSort(0, 20), //top 20 boards sorted by users, pph, total posts
Files.activeContent() //size ans number of files
Files.activeContent(), //size ans number of files
News.find(maxRecentNews), //some recent newsposts
]);
const html = await render('index.html', 'home.pug', {
totalStats,
boards,
fileStats,
recentNews,
});
const end = process.hrtime(start);
debugLogs && console.log(timeDiffString(label, end));

@ -16,6 +16,22 @@ block content
| This is an anonymous imageboard, a type of BBS where anyone can post messages and share images.
| You don't need to register or provide any personal information to make a post.
| Choose a board below to join the discussion, or #[a(href='/create.html') create your own].
if recentNews && recentNews.length > 0
.table-container.flex-center.mv-5
table.newstable
tr
th(colspan=3)
a(href='/news.html') Latest News
each post in recentNews
tr
td
a.left(href=`/news.html#${post._id}`) #{post.title}
td
p.no-m-p #{`${post.message.raw.substring(0,50)}${post.message.raw.length > 50 ? '...' : ''}`}
td
- const newsDate = new Date(post.date);
time.right.reltime(datetime=newsDate.toISOString()) #{newsDate.toLocaleString(undefined, {hour12:false})}
if boards && boards.length > 0
include ../includes/boardtable.pug
each board in boards

Loading…
Cancel
Save