You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
nodebb/src/controllers/categories.js

84 lines
2.1 KiB
JavaScript

"use strict";
var async = require('async');
var nconf = require('nconf');
var validator = require('validator');
var categories = require('../categories');
var meta = require('../meta');
var plugins = require('../plugins');
var helpers = require('./helpers');
var categoriesController = {};
categoriesController.list = function(req, res, next) {
res.locals.metaTags = [{
name: "title",
content: validator.escape(meta.config.title || 'NodeBB')
}, {
name: "description",
content: validator.escape(meta.config.description || '')
}, {
property: 'og:title',
content: '[[pages:categories]]'
}, {
property: 'og:type',
content: 'website'
}];
if (meta.config['brand:logo']) {
9 years ago
var brandLogo = meta.config['brand:logo'];
if (!brandLogo.startsWith('http')) {
brandLogo = nconf.get('url') + brandLogo;
}
res.locals.metaTags.push({
property: 'og:image',
9 years ago
content: brandLogo
});
10 years ago
}
var categoryData;
async.waterfall([
function (next) {
categories.getCategoriesByPrivilege('cid:0:children', req.uid, 'find', next);
11 years ago
},
function (_categoryData, next) {
categoryData = _categoryData;
10 years ago
var allCategories = [];
categories.flattenCategories(allCategories, categoryData);
11 years ago
categories.getRecentTopicReplies(allCategories, req.uid, next);
}
9 years ago
], function(err) {
if (err) {
return next(err);
}
9 years ago
var data = {
title: '[[pages:categories]]',
categories: categoryData
};
if (req.path.startsWith('/api/categories') || req.path.startsWith('/categories')) {
data.breadcrumbs = helpers.buildBreadcrumbs([{text: data.title}]);
}
data.categories.forEach(function(category) {
if (category && Array.isArray(category.posts) && category.posts.length) {
category.teaser = {
url: nconf.get('relative_path') + '/topic/' + category.posts[0].topic.slug + '/' + category.posts[0].index,
timestampISO: category.posts[0].timestampISO,
pid: category.posts[0].pid
};
}
});
plugins.fireHook('filter:categories.get', data, function(err, data) {
res.render('categories', data);
});
});
};
module.exports = categoriesController;