nodebb-plugin-link-preview 2.0.15 → 2.1.0
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 +41 -18
- package/package-lock.json +2 -2
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -90,16 +90,8 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const requests = new Map();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
attachmentData.filter(Boolean).forEach(({ url, _type }) => {
|
|
96
|
-
const isInlineImage = new RegExp(`<img.+?src="${url}".+?>`).test(content);
|
|
97
|
-
if (!isInlineImage) {
|
|
98
|
-
const type = _type || 'attachment';
|
|
99
|
-
requests.set(url, { type });
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
93
|
+
let attachmentHtml = '';
|
|
94
|
+
let placeholderHtml = '';
|
|
103
95
|
|
|
104
96
|
// Parse inline urls
|
|
105
97
|
const $ = load(content, null, false);
|
|
@@ -108,6 +100,7 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
108
100
|
|
|
109
101
|
// Skip if the anchor has link text, or has text on the same line.
|
|
110
102
|
let url = $anchor.attr('href');
|
|
103
|
+
url = decodeURI(url);
|
|
111
104
|
const text = $anchor.text();
|
|
112
105
|
const hasSiblings = !!anchor.prev || !!anchor.next;
|
|
113
106
|
if (hasSiblings || url !== text || anchor.parent.name !== 'p') {
|
|
@@ -134,9 +127,27 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
134
127
|
});
|
|
135
128
|
}
|
|
136
129
|
|
|
130
|
+
// Post attachments
|
|
131
|
+
if (pid && Array.isArray(attachments) && attachments.length) {
|
|
132
|
+
const attachmentData = await posts.attachments.getAttachments(attachments);
|
|
133
|
+
await Promise.all(attachmentData.filter(Boolean).map(async ({ url, _type }) => {
|
|
134
|
+
const isInlineImage = new RegExp(`<img.+?src="${url}".+?>`).test(content);
|
|
135
|
+
if (isInlineImage) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const special = await handleSpecialEmbed(url);
|
|
140
|
+
if (special) {
|
|
141
|
+
attachmentHtml += special;
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const type = _type || 'attachment';
|
|
146
|
+
requests.set(url, { type });
|
|
147
|
+
}));
|
|
148
|
+
}
|
|
149
|
+
|
|
137
150
|
// Render cache hits immediately
|
|
138
|
-
let attachmentHtml = '';
|
|
139
|
-
let placeholderHtml = '';
|
|
140
151
|
const cold = new Set();
|
|
141
152
|
await Promise.all(Array.from(requests.keys()).map(async (url) => {
|
|
142
153
|
const options = requests.get(url);
|
|
@@ -279,25 +290,37 @@ async function handleSpecialEmbed(url, $anchor) {
|
|
|
279
290
|
video = searchParams.get('v');
|
|
280
291
|
}
|
|
281
292
|
const html = await app.renderAsync(short ? 'partials/link-preview/youtube-short' : 'partials/link-preview/youtube', { video });
|
|
282
|
-
$anchor.replaceWith(html);
|
|
283
293
|
|
|
284
|
-
|
|
294
|
+
if ($anchor) {
|
|
295
|
+
$anchor.replaceWith(html);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return html;
|
|
285
300
|
}
|
|
286
301
|
|
|
287
302
|
if (embedVimeo === 'on' && hostname === 'vimeo.com') {
|
|
288
303
|
const video = pathname.slice(1);
|
|
289
304
|
const html = await app.renderAsync('partials/link-preview/vimeo', { video });
|
|
290
|
-
$anchor.replaceWith(html);
|
|
291
305
|
|
|
292
|
-
|
|
306
|
+
if ($anchor) {
|
|
307
|
+
$anchor.replaceWith(html);
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return html;
|
|
293
312
|
}
|
|
294
313
|
|
|
295
314
|
if (embedTiktok === 'on' && ['tiktok.com', 'www.tiktok.com'].some(x => hostname === x)) {
|
|
296
315
|
const video = pathname.split('/')[3];
|
|
297
316
|
const html = await app.renderAsync('partials/link-preview/tiktok', { video });
|
|
298
|
-
$anchor.replaceWith(html);
|
|
299
317
|
|
|
300
|
-
|
|
318
|
+
if ($anchor) {
|
|
319
|
+
$anchor.replaceWith(html);
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return html;
|
|
301
324
|
}
|
|
302
325
|
|
|
303
326
|
return false;
|
package/package-lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nodebb-plugin-link-preview",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "nodebb-plugin-link-preview",
|
|
9
|
-
"version": "2.0
|
|
9
|
+
"version": "2.1.0",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"cheerio": "^1.0.0-rc.12",
|