forked from NodeBB/nodebb-plugin-custom-homepage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.js
115 lines (93 loc) · 2.7 KB
/
library.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
(function(Plugin) {
"use strict";
var categories = require.main.require('./src/categories');
var topics = require.main.require('./src/topics');
var meta = require.main.require('./src/meta');
var User = module.parent.require('./user');
// init hook
Plugin.serveHomepage = function(params){
renderExampleCategories(params.req, params.res, params.next);
//renderExampleRecent(params.req, params.res, params.next);
};
function renderExampleCategories(req, res, next) {
// Get all the visible categories.
var stop = (parseInt(meta.config.topicsPerList, 10) || 22) - 1;
categories.getCategoriesByPrivilege('cid:0:children', req.uid, 'find', function(err, categoryData) {
if (err) return next(err);
// Put the categories in a tree format.
categories.flattenCategories([], categoryData);
var categoriasLocales = {};
categoriasLocales.cat = categoryData;
topics.getTopicsFromSet('topics:recent', req.uid, 0, stop, function(err, data) {
if (err) return next(err);
categoriasLocales.topics= data.topics;
User.getUserFields(req.uid, ['username','userslug', 'topiccount', 'postcount','reputation','icon:bgColor','icon:text','picture','groupTitle'], function (err, user) {
if (err || !user) user = null;
res.render('homepage', {
template: { name: 'homepage' },
topics: categoriasLocales.topics,
categories: categoriasLocales.cat,
user: user
});
});
});
});
}
/*
function renderExampleRecent(req, res, next){
var stop = (parseInt(meta.config.topicsPerList, 10) || 20) - 1;
topics.getTopicsFromSet('topics:recent', req.uid, 0, stop, function(err, data) {
if (err) return next(err);
res.render('homepage', {
template: { name: 'homepage' },
topics: data.topics
});
});
}
*/
Plugin.addListing = function(data, callback){
data.routes.push({
route: 'customHP',
name: 'Custom Homepage'
});
callback(null, data);
};
Plugin.addNavigation = function(header, callback) {
header.navigation.push(
{
route: '/categories',
class: '',
text: 'Forum',
iconClass: 'fa-comments',
title: 'Forum',
textClass: 'visible-xs-inline'
}
);
callback(null, header);
};
Plugin.defineWidgetAreas = function(areas, callback) {
areas = areas.concat([
{
'name': 'Custom HP Header',
'template': 'homepage.tpl',
'location': 'hp-header'
},
{
'name': 'Custom HP Footer',
'template': 'homepage.tpl',
'location': 'hp-footer'
},
{
'name': 'Custom HP Sidebar',
'template': 'homepage.tpl',
'location': 'hp-sidebar'
},
{
'name': 'Custom HP Content',
'template': 'homepage.tpl',
'location': 'hp-content'
}
]);
callback(null, areas);
};
}(exports));