forked from digitalLumberjack/nodebb-plugin-topic-tags
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary.js
54 lines (40 loc) · 2.21 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
'use strict';
var Meta = require.main.require('./src/meta');
var TopicTags = {};
var ignoredList = ['the', 'be', 'to', 'of', 'and', 'a', 'in', 'that', 'have', 'i', 'it', 'for', 'not', 'on', 'with', 'he', 'as', 'you', 'do', 'at', 'this', 'but', 'his', 'by', 'from', 'they', 'we', 'say', 'her', 'she', 'or', 'an', 'will', 'my', 'one', 'all', 'would', 'there', 'their', 'what', 'so', 'up', 'out', 'if', 'about', 'who', 'get', 'which', 'go', 'me', 'when', 'make', 'can', 'like', 'time', 'no', 'just', 'him', 'know', 'take', 'people', 'into', 'year', 'your', 'good', 'some', 'could', 'them', 'see', 'other', 'than', 'then', 'now', 'look', 'only', 'come', 'its', 'over', 'think', 'also', 'back', 'after', 'use', 'two', 'how', 'our', 'work', 'first', 'well', 'way', 'even', 'new', 'want', 'because', 'any', 'these', 'give', 'day', 'most', 'us', 'has', 'once', 'again', 'let', 'lets', 'try'];
var adminIgnoreList = [];
TopicTags.init = function(params, callback) {
var app = params.router;
var middleware = params.middleware;
Meta.settings.get('topic-tags', function(err, settings) {
if (!err && settings.ignoredWords) {
adminIgnoreList = settings.ignoredWords.split(/[\s,]+/).join().split(",");
}
ignoredList = ignoredList.concat(adminIgnoreList);
});
app.get('/admin/plugins/topic-tags', middleware.admin.buildHeader, renderAdmin);
app.get('/api/admin/plugins/topic-tags', renderAdmin);
callback();
};
TopicTags.addTags = function(data, callback) {
var tags = data.title.replace(/(?:https?|ftp):\/\/[\n\S]+/g, '').replace(/[&\/\\#,+()$~%'":*?<>{}]/g, '').split(" ");
function isValidAndNotIgnored (value) {
return ignoredList.indexOf(value.toLowerCase()) === -1 && value.length >= Meta.config.minimumTagLength && value.length <= Meta.config.maximumTagLength;
}
if (data.tags.length === 0) {
data.tags = tags.filter(isValidAndNotIgnored);
}
callback(null, data);
};
TopicTags.addAdminNavigation = function(header, callback) {
header.plugins.push({
route: '/plugins/topic-tags',
icon: 'fa-paint-brush',
name: 'Topic Tags'
});
callback(null, header);
};
function renderAdmin(req, res, next) {
res.render('admin/plugins/topic-tags', {});
}
module.exports = TopicTags;