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.
- package/library.js +12 -36
- package/package.json +1 -1
- 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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
//
|
|
41
|
-
str = str.replace(/\
|
|
42
|
-
|
|
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:
|
|
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
package/plugin.json
CHANGED