nodebb-plugin-onekite-discord 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library.js +28 -7
- package/package.json +1 -1
- package/plugin.json +3 -4
package/library.js
CHANGED
|
@@ -41,6 +41,26 @@ function ensureAbsoluteUrl(baseUrl, maybeUrl) {
|
|
|
41
41
|
return s;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
|
|
45
|
+
function normalizeExcerptLinks(input) {
|
|
46
|
+
if (!input) return '';
|
|
47
|
+
let s = String(input);
|
|
48
|
+
|
|
49
|
+
// Convert HTML anchors to "text (url)" before stripping HTML
|
|
50
|
+
s = s.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi, (m, href, inner) => {
|
|
51
|
+
const text = stripHtml(inner).trim() || href;
|
|
52
|
+
return `${text} (${href})`;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Convert Markdown links [text](url) to "text (url)"
|
|
56
|
+
s = s.replace(/\[([^\]]+)\]\(([^\s)]+)\)/g, (m, label, url) => `${label} (${url})`);
|
|
57
|
+
|
|
58
|
+
// Fix common malformed scheme "https:/example.com" -> "https://example.com"
|
|
59
|
+
s = s.replace(/\b(https?):\/(?!\/)/g, '$1://');
|
|
60
|
+
|
|
61
|
+
return s;
|
|
62
|
+
}
|
|
63
|
+
|
|
44
64
|
function stripHtml(html) {
|
|
45
65
|
if (!html) return '';
|
|
46
66
|
return String(html)
|
|
@@ -142,7 +162,8 @@ async function getPostExcerpt(pid) {
|
|
|
142
162
|
if (!pid) return '';
|
|
143
163
|
try {
|
|
144
164
|
const p = await posts.getPostFields(pid, ['content']);
|
|
145
|
-
const
|
|
165
|
+
const normalized = normalizeExcerptLinks(p && p.content);
|
|
166
|
+
const text = stripHtml(normalized);
|
|
146
167
|
return truncate(text, 500);
|
|
147
168
|
} catch {
|
|
148
169
|
return '';
|
|
@@ -166,18 +187,18 @@ async function buildEmbed({ tid, pid, isReply }) {
|
|
|
166
187
|
const targetUrl = (isReply && pid) ? `${topicUrl}/${pid}` : topicUrl;
|
|
167
188
|
|
|
168
189
|
const baseTitle = decodeHtmlEntities((topicData.title || (isReply ? 'Nouvelle réponse' : 'Nouveau sujet')).toString());
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const safeTitle =
|
|
190
|
+
const titleWithCategory = categoryName ? `[${categoryName}] ${baseTitle}` : baseTitle;
|
|
191
|
+
const replyIcon = isReply ? '↪️ ' : '';
|
|
192
|
+
|
|
193
|
+
const safeTitle = titleWithCategory.slice(0, 256);
|
|
173
194
|
|
|
174
195
|
const excerpt = await getPostExcerpt(isReply ? pid : topicData.mainPid);
|
|
175
196
|
|
|
176
197
|
const postForUser = await posts.getPostFields(isReply ? pid : topicData.mainPid, ['uid']);
|
|
177
198
|
const username = await user.getUserField(postForUser.uid, 'username');
|
|
178
199
|
|
|
179
|
-
// Tout le titre dans l'embed : "[Catégorie] Titre
|
|
180
|
-
const embedTitle = `${safeTitle}
|
|
200
|
+
// Tout le titre dans l'embed : "↪️ [Catégorie] Titre – Pseudo" (pseudo sans lien)
|
|
201
|
+
const embedTitle = `${replyIcon}${safeTitle} – ${username}`.slice(0, 256);
|
|
181
202
|
|
|
182
203
|
// Embed title becomes clickable via embed.url
|
|
183
204
|
return { topicData, content: '', embed: { title: embedTitle, url: targetUrl, description: excerpt || '' } };
|
package/package.json
CHANGED
package/plugin.json
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "nodebb-plugin-onekite-discord",
|
|
3
3
|
"name": "Discord Onekite Notifier",
|
|
4
|
-
"description": "Notifie Discord via webhook pour nouveaux sujets et/ou
|
|
5
|
-
"library": "./library.js",
|
|
4
|
+
"description": "Notifie Discord via webhook pour nouveaux sujets et/ou réponses (NodeBB v4.x).",
|
|
6
5
|
"hooks": [
|
|
7
6
|
{
|
|
8
7
|
"hook": "static:app.load",
|
|
@@ -32,5 +31,5 @@
|
|
|
32
31
|
"acpScripts": [
|
|
33
32
|
"public/admin.js"
|
|
34
33
|
],
|
|
35
|
-
"version": "1.0.
|
|
36
|
-
}
|
|
34
|
+
"version": "1.0.7"
|
|
35
|
+
}
|