Files
NodeBB/src/controllers/popular.js

33 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-08-17 16:38:05 -04:00
'use strict';
2019-07-31 12:39:15 -04:00
const nconf = require('nconf');
const validator = require('validator');
2018-06-18 14:37:32 -04:00
2019-07-31 12:39:15 -04:00
const helpers = require('./helpers');
const recentController = require('./recent');
2015-08-17 16:38:05 -04:00
2019-07-31 12:39:15 -04:00
const popularController = module.exports;
2015-08-17 16:38:05 -04:00
2019-07-31 12:39:15 -04:00
popularController.get = async function (req, res, next) {
const data = await recentController.getData(req, 'popular', 'posts');
if (!data) {
return next();
}
const term = helpers.terms[req.query.term] || 'alltime';
2021-02-03 23:59:08 -07:00
if (req.originalUrl.startsWith(`${nconf.get('relative_path')}/api/popular`) || req.originalUrl.startsWith(`${nconf.get('relative_path')}/popular`)) {
data.title = `[[pages:popular-${term}]]`;
2019-07-31 12:39:15 -04:00
const breadcrumbs = [{ text: '[[global:header.popular]]' }];
data.breadcrumbs = helpers.buildBreadcrumbs(breadcrumbs);
}
if (!data['feeds:disableRSS'] && data.rssFeedUrl) {
const feedQs = data.rssFeedUrl.split('?')[1];
data.rssFeedUrl = `${nconf.get('relative_path')}/popular/${validator.escape(String(req.query.term || 'alltime'))}.rss`;
if (req.loggedIn) {
data.rssFeedUrl += `?${feedQs}`;
}
2019-07-31 12:39:15 -04:00
}
res.render('popular', data);
2015-08-17 16:38:05 -04:00
};