|
|
|
@ -1,15 +1,14 @@
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var nconf = require('nconf');
|
|
|
|
|
const nconf = require('nconf');
|
|
|
|
|
|
|
|
|
|
var categories = require('../categories');
|
|
|
|
|
var meta = require('../meta');
|
|
|
|
|
var helpers = require('./helpers');
|
|
|
|
|
const categories = require('../categories');
|
|
|
|
|
const meta = require('../meta');
|
|
|
|
|
const helpers = require('./helpers');
|
|
|
|
|
|
|
|
|
|
var categoriesController = module.exports;
|
|
|
|
|
const categoriesController = module.exports;
|
|
|
|
|
|
|
|
|
|
categoriesController.list = function (req, res, next) {
|
|
|
|
|
categoriesController.list = async function (req, res) {
|
|
|
|
|
res.locals.metaTags = [{
|
|
|
|
|
name: 'title',
|
|
|
|
|
content: String(meta.config.title || 'NodeBB'),
|
|
|
|
@ -18,45 +17,34 @@ categoriesController.list = function (req, res, next) {
|
|
|
|
|
content: 'website',
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
var categoryData;
|
|
|
|
|
let tree;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find', next);
|
|
|
|
|
},
|
|
|
|
|
function (_categoryData, next) {
|
|
|
|
|
categoryData = _categoryData;
|
|
|
|
|
|
|
|
|
|
tree = categories.getTree(categoryData, 0);
|
|
|
|
|
categories.getRecentTopicReplies(categoryData, req.uid, next);
|
|
|
|
|
},
|
|
|
|
|
function () {
|
|
|
|
|
var data = {
|
|
|
|
|
title: meta.config.homePageTitle || '[[pages:home]]',
|
|
|
|
|
categories: tree,
|
|
|
|
|
const categoryData = await categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find');
|
|
|
|
|
const tree = categories.getTree(categoryData, 0);
|
|
|
|
|
await categories.getRecentTopicReplies(categoryData, req.uid);
|
|
|
|
|
|
|
|
|
|
const data = {
|
|
|
|
|
title: meta.config.homePageTitle || '[[pages:home]]',
|
|
|
|
|
categories: tree,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/categories') || req.originalUrl.startsWith(nconf.get('relative_path') + '/categories')) {
|
|
|
|
|
data.title = '[[pages:categories]]';
|
|
|
|
|
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: data.title }]);
|
|
|
|
|
res.locals.metaTags.push({
|
|
|
|
|
property: 'og:title',
|
|
|
|
|
content: '[[pages:categories]]',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.categories.forEach(function (category) {
|
|
|
|
|
if (category && Array.isArray(category.posts) && category.posts.length && category.posts[0]) {
|
|
|
|
|
category.teaser = {
|
|
|
|
|
url: nconf.get('relative_path') + '/post/' + category.posts[0].pid,
|
|
|
|
|
timestampISO: category.posts[0].timestampISO,
|
|
|
|
|
pid: category.posts[0].pid,
|
|
|
|
|
topic: category.posts[0].topic,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (req.originalUrl.startsWith(nconf.get('relative_path') + '/api/categories') || req.originalUrl.startsWith(nconf.get('relative_path') + '/categories')) {
|
|
|
|
|
data.title = '[[pages:categories]]';
|
|
|
|
|
data.breadcrumbs = helpers.buildBreadcrumbs([{ text: data.title }]);
|
|
|
|
|
res.locals.metaTags.push({
|
|
|
|
|
property: 'og:title',
|
|
|
|
|
content: '[[pages:categories]]',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.categories.forEach(function (category) {
|
|
|
|
|
if (category && Array.isArray(category.posts) && category.posts.length && category.posts[0]) {
|
|
|
|
|
category.teaser = {
|
|
|
|
|
url: nconf.get('relative_path') + '/post/' + category.posts[0].pid,
|
|
|
|
|
timestampISO: category.posts[0].timestampISO,
|
|
|
|
|
pid: category.posts[0].pid,
|
|
|
|
|
topic: category.posts[0].topic,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res.render('categories', data);
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
res.render('categories', data);
|
|
|
|
|
};
|
|
|
|
|