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.
67 lines
1.4 KiB
JavaScript
67 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
var async = require('async');
|
|
|
|
var db = require('../../database');
|
|
var categories = require('../../categories');
|
|
var privileges = require('../../privileges');
|
|
var plugins = require('../../plugins');
|
|
|
|
var homePageController = {};
|
|
|
|
|
|
homePageController.get = function (req, res, next) {
|
|
async.waterfall([
|
|
function (next) {
|
|
db.getSortedSetRange('categories:cid', 0, -1, next);
|
|
},
|
|
function (cids, next) {
|
|
privileges.categories.filterCids('find', cids, 0, next);
|
|
},
|
|
function (cids, next) {
|
|
categories.getCategoriesFields(cids, ['name', 'slug'], next);
|
|
},
|
|
function (categoryData, next) {
|
|
categoryData = categoryData.map(function (category) {
|
|
return {
|
|
route: 'category/' + category.slug,
|
|
name: 'Category: ' + category.name,
|
|
};
|
|
});
|
|
next(null, categoryData);
|
|
},
|
|
], function (err, categoryData) {
|
|
if (err || !categoryData) {
|
|
categoryData = [];
|
|
}
|
|
|
|
plugins.fireHook('filter:homepage.get', { routes: [
|
|
{
|
|
route: 'categories',
|
|
name: 'Categories',
|
|
},
|
|
{
|
|
route: 'recent',
|
|
name: 'Recent',
|
|
},
|
|
{
|
|
route: 'popular',
|
|
name: 'Popular',
|
|
},
|
|
].concat(categoryData) }, function (err, data) {
|
|
if (err) {
|
|
return next(err);
|
|
}
|
|
|
|
data.routes.push({
|
|
route: '',
|
|
name: 'Custom',
|
|
});
|
|
|
|
res.render('admin/general/homepage', data);
|
|
});
|
|
});
|
|
};
|
|
|
|
module.exports = homePageController;
|