mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-29 18:16:17 +01:00
Add Custom and Category homepages.
This commit is contained in:
23
public/src/admin/general/homepage.js
Normal file
23
public/src/admin/general/homepage.js
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
/*global define*/
|
||||
|
||||
define('admin/general/homepage', ['admin/settings'], function(Settings) {
|
||||
|
||||
function toggleCustomRoute() {
|
||||
if ($('[data-field="homePageRoute"]').val()) {
|
||||
$('#homePageCustom').hide();
|
||||
}else{
|
||||
$('#homePageCustom').show();
|
||||
}
|
||||
}
|
||||
|
||||
var Homepage = {};
|
||||
|
||||
Homepage.init = function() {
|
||||
$('[data-field="homePageRoute"]').on('change', toggleCustomRoute);
|
||||
|
||||
toggleCustomRoute();
|
||||
};
|
||||
|
||||
return Homepage;
|
||||
});
|
||||
@@ -348,21 +348,55 @@ adminController.navigation.get = function(req, res, next) {
|
||||
};
|
||||
|
||||
adminController.homepage.get = function(req, res, next) {
|
||||
plugins.fireHook('filter:homepage.get', {routes: [
|
||||
{
|
||||
route: 'categories',
|
||||
name: 'Categories'
|
||||
},
|
||||
{
|
||||
route: 'recent',
|
||||
name: 'Recent'
|
||||
},
|
||||
{
|
||||
route: 'popular',
|
||||
name: 'Popular'
|
||||
async.parallel({
|
||||
categoryData: function(next) {
|
||||
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.getMultipleCategoryFields(cids, ['name', 'slug'], next);
|
||||
},
|
||||
function(categoryData, next) {
|
||||
async.map(categoryData, function(category, next) {
|
||||
var route = 'category/' + category.slug,
|
||||
hook = 'action:homepage.get:' + route;
|
||||
|
||||
next(null, {
|
||||
route: route,
|
||||
name: 'Category: ' + category.name
|
||||
});
|
||||
}, next);
|
||||
}
|
||||
], next);
|
||||
}
|
||||
]}, function(err, data) {
|
||||
res.render('admin/general/homepage', data);
|
||||
}, function(err, results) {
|
||||
if (err || !results || !results.categoryData) results = {categoryData:[]};
|
||||
|
||||
plugins.fireHook('filter:homepage.get', {routes: [
|
||||
{
|
||||
route: 'categories',
|
||||
name: 'Categories'
|
||||
},
|
||||
{
|
||||
route: 'recent',
|
||||
name: 'Recent'
|
||||
},
|
||||
{
|
||||
route: 'popular',
|
||||
name: 'Popular'
|
||||
}
|
||||
].concat(results.categoryData)}, function(err, data) {
|
||||
data.routes.push({
|
||||
route: '',
|
||||
name: 'Custom'
|
||||
});
|
||||
|
||||
res.render('admin/general/homepage', data);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -33,20 +33,20 @@ var Controllers = {
|
||||
|
||||
|
||||
Controllers.home = function(req, res, next) {
|
||||
var route = meta.config.homePageRoute || 'categories',
|
||||
var route = meta.config.homePageRoute || meta.config.homePageCustom || 'categories',
|
||||
hook = 'action:homepage.get:' + route;
|
||||
|
||||
if (plugins.hasListeners(hook)) {
|
||||
plugins.fireHook(hook, {req: req, res: res, next: next});
|
||||
} else {
|
||||
if (route === 'categories') {
|
||||
if (route === 'categories' || route === '/') {
|
||||
Controllers.categories.list(req, res, next);
|
||||
} else if (route === 'recent') {
|
||||
Controllers.recent.get(req, res, next);
|
||||
} else if (route === 'popular') {
|
||||
Controllers.popular.get(req, res, next);
|
||||
} else {
|
||||
next();
|
||||
res.redirect(route);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -12,6 +12,11 @@
|
||||
<option value="{routes.route}">{routes.name}</option>
|
||||
<!-- END routes -->
|
||||
</select>
|
||||
<br>
|
||||
<div id="homePageCustom" style="display: none;">
|
||||
<label>Custom Route</label>
|
||||
<input type="text" class="form-control" data-field="homePageCustom"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user