nodebb-plugin-onekite-discord 1.0.15 → 1.0.16

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.
Files changed (3) hide show
  1. package/library.js +12 -36
  2. package/package.json +1 -1
  3. package/plugin.json +1 -1
package/library.js CHANGED
@@ -2,46 +2,22 @@
2
2
 
3
3
 
4
4
 
5
- /**
6
- * Discord embed descriptions do not support masked links like [text](url).
7
- * To keep links clickable, flatten any link-like markup into plain URLs,
8
- * which Discord auto-linkifies.
9
- */
10
- function flattenLinksToUrls(str) {
11
- if (!str || typeof str !== 'string') return str;
12
5
 
13
- const normalizeUrl = (u) => {
14
- if (!u) return '';
15
- let url = String(u).trim();
16
- url = url.replace(/^<(.+)>$/, '$1');
17
- // fix common typos
18
- url = url.replace(/^https:\//i, 'https://');
19
- url = url.replace(/^http:\//i, 'http://');
20
- // add scheme for bare www.
21
- if (/^www\./i.test(url)) url = 'https://' + url;
22
- return url;
23
- };
24
6
 
25
- // HTML links -> URL
26
- str = str.replace(/<a\s+[^>]*href=["']([^"']+)["'][^>]*>.*?<\/a>/gi, (_m, href) => {
27
- return normalizeUrl(href);
28
- });
29
7
 
30
- // Markdown masked links -> URL
31
- str = str.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, _text, url) => {
32
- return normalizeUrl(url);
33
- });
34
8
 
35
- // NodeBB rendered: "texte du lien(url)" or "texte du lien (url)" -> URL
36
- str = str.replace(/([^\n\r()]{1,200}?)\s*\((https?:\/\/[^)\s]+|www\.[^)\s]+)\)/g, (_m, _text, url) => {
37
- return normalizeUrl(url);
38
- });
9
+ /**
10
+ * Simplified:
11
+ * - Convert masked markdown links: [text](url) -> url
12
+ * - Do NOT modify anything else.
13
+ * Discord will auto-linkify URLs if it can.
14
+ */
15
+ function simplifyMaskedLinks(str) {
16
+ if (!str || typeof str !== 'string') return str;
39
17
 
40
- // Ensure bare "www.xxx" tokens become "https://www.xxx"
41
- str = str.replace(/\b(www\.[^\s<>()]+)\b/g, (_m, url) => {
42
- // strip trailing punctuation
43
- const clean = url.replace(/[),.;!?]+$/g, '');
44
- return normalizeUrl(clean);
18
+ // [text](url) -> url (as-is)
19
+ str = str.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, _text, url) => {
20
+ return url;
45
21
  });
46
22
 
47
23
  return str;
@@ -227,7 +203,7 @@ async function buildEmbed({ tid, pid, isReply }) {
227
203
  const embedTitle = `${replyIcon}${safeTitle} – ${username}`.slice(0, 256);
228
204
 
229
205
  // Embed title becomes clickable via embed.url
230
- return { topicData, content: '', embed: { title: embedTitle, url: targetUrl, description: flattenLinksToUrls(excerpt || '') } };
206
+ return { topicData, content: '', embed: { title: embedTitle, url: targetUrl, description: simplifyMaskedLinks(excerpt || '') } };
231
207
  }
232
208
 
233
209
  function extractTidPid(data) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-onekite-discord",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Discord webhook notifier for Onekite (NodeBB v4.x only)",
5
5
  "main": "library.js",
6
6
  "license": "MIT",
package/plugin.json CHANGED
@@ -31,5 +31,5 @@
31
31
  "acpScripts": [
32
32
  "public/admin.js"
33
33
  ],
34
- "version": "1.0.15"
34
+ "version": "1.0.16"
35
35
  }