Skip to content

Commit 25ebcf0

Browse files
committed
filter topic data on the way out
1 parent 6da3c35 commit 25ebcf0

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

index.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ var Beep = {
114114
return callback(null, data);
115115
}
116116
data.postData.content = Beep.parseContent(data.postData.content);
117+
if (data.postData.topic) {
118+
Beep.parseTopic(data.postData.topic)
119+
}
117120
callback(null, data);
118121
},
119122
parseRaw: function (content, callback) {
@@ -130,15 +133,31 @@ var Beep = {
130133
data.userData.signature = Beep.parseContent(data.userData.signature);
131134
callback(null, data);
132135
},
133-
parseTopic: function (data, callback) {
134-
// from http://htmlarrows.com/symbols/
135-
var starHTML = '⁎';
136-
data.topic.title = Beep.parseContent(data.topic.title, starHTML);
137-
data.topic.slug = Beep.parseContent(data.topic.slug, starHTML);
138-
data.topic.titleRaw = Beep.parseContent(data.topic.titleRaw, starHTML);
139-
136+
onTopicsGet: function (data, callback) {
137+
data.topics.forEach(Beep.parseTopic);
138+
callback(null, data);
139+
},
140+
onTopicGet: function (data, callback) {
141+
Beep.parseTopic(data.topic);
142+
callback(null, data);
143+
},
144+
onGetPostSummaries: function (data, callback) {
145+
data.posts.forEach(function (post) {
146+
if (post) {
147+
Beep.parseTopic(post.topic);
148+
}
149+
});
140150
callback(null, data);
141151
},
152+
parseTopic: function (topic) {
153+
var starHTML = '⁎';
154+
if (topic) {
155+
topic.title = Beep.parseContent(topic.title, starHTML);
156+
topic.slug = Beep.parseContent(topic.slug, starHTML);
157+
topic.titleRaw = Beep.parseContent(topic.titleRaw, starHTML);
158+
}
159+
return topic;
160+
},
142161
filterTags: function (data, callback) {
143162
var match;
144163
data.tags.some(function (tag) {

plugin.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
{ "hook": "filter:parse.signature", "method": "parseSignature" },
1717
{ "hook": "filter:post.getFields", "method": "post.getFields"},
1818

19-
{ "hook": "filter:topic.create", "method": "parseTopic" },
20-
{ "hook": "filter:topic.edit", "method": "parseTopic" },
19+
{ "hook": "filter:topics.get", "method": "onTopicsGet" },
20+
{ "hook": "filter:topic.get", "method": "onTopicGet" },
21+
{ "hook": "filter:post.getPostSummaryByPids", "method": "onGetPostSummaries" },
22+
2123
{ "hook": "filter:tags.filter", "method": "filterTags" },
2224

2325
{ "hook": "filter:topic.create", "method": "checkForIllegalWords" },

0 commit comments

Comments
 (0)