mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
getHomePageRoutes
This commit is contained in:
@@ -39,50 +39,7 @@ settingsController.get = function(req, res, callback) {
|
|||||||
languages.list(next);
|
languages.list(next);
|
||||||
},
|
},
|
||||||
homePageRoutes: function(next) {
|
homePageRoutes: function(next) {
|
||||||
async.waterfall([
|
getHomePageRoutes(next);
|
||||||
function(next) {
|
|
||||||
db.getSortedSetRange('cid:0:children', 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) {
|
|
||||||
data.routes.push({
|
|
||||||
route: 'custom',
|
|
||||||
name: 'Custom'
|
|
||||||
});
|
|
||||||
|
|
||||||
next(null, data.routes);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID)
|
sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID)
|
||||||
}, next);
|
}, next);
|
||||||
@@ -161,5 +118,59 @@ settingsController.get = function(req, res, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
function getHomePageRoutes(callback) {
|
||||||
|
async.waterfall([
|
||||||
|
function (next) {
|
||||||
|
db.getSortedSetRange('cid:0:children', 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) {
|
||||||
|
return callback(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 callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
data.routes.push({
|
||||||
|
route: 'custom',
|
||||||
|
name: 'Custom'
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, data.routes);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = settingsController;
|
module.exports = settingsController;
|
||||||
Reference in New Issue
Block a user