nodebb-plugin-link-preview 2.0.16 → 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 -19
- 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,7 +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');
|
|
111
|
-
url = decodeURI(url);
|
|
103
|
+
url = decodeURI(url);
|
|
112
104
|
const text = $anchor.text();
|
|
113
105
|
const hasSiblings = !!anchor.prev || !!anchor.next;
|
|
114
106
|
if (hasSiblings || url !== text || anchor.parent.name !== 'p') {
|
|
@@ -135,9 +127,27 @@ async function process(content, { type, pid, tid, attachments }) {
|
|
|
135
127
|
});
|
|
136
128
|
}
|
|
137
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
|
+
|
|
138
150
|
// Render cache hits immediately
|
|
139
|
-
let attachmentHtml = '';
|
|
140
|
-
let placeholderHtml = '';
|
|
141
151
|
const cold = new Set();
|
|
142
152
|
await Promise.all(Array.from(requests.keys()).map(async (url) => {
|
|
143
153
|
const options = requests.get(url);
|
|
@@ -280,25 +290,37 @@ async function handleSpecialEmbed(url, $anchor) {
|
|
|
280
290
|
video = searchParams.get('v');
|
|
281
291
|
}
|
|
282
292
|
const html = await app.renderAsync(short ? 'partials/link-preview/youtube-short' : 'partials/link-preview/youtube', { video });
|
|
283
|
-
$anchor.replaceWith(html);
|
|
284
293
|
|
|
285
|
-
|
|
294
|
+
if ($anchor) {
|
|
295
|
+
$anchor.replaceWith(html);
|
|
296
|
+
return true;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return html;
|
|
286
300
|
}
|
|
287
301
|
|
|
288
302
|
if (embedVimeo === 'on' && hostname === 'vimeo.com') {
|
|
289
303
|
const video = pathname.slice(1);
|
|
290
304
|
const html = await app.renderAsync('partials/link-preview/vimeo', { video });
|
|
291
|
-
$anchor.replaceWith(html);
|
|
292
305
|
|
|
293
|
-
|
|
306
|
+
if ($anchor) {
|
|
307
|
+
$anchor.replaceWith(html);
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return html;
|
|
294
312
|
}
|
|
295
313
|
|
|
296
314
|
if (embedTiktok === 'on' && ['tiktok.com', 'www.tiktok.com'].some(x => hostname === x)) {
|
|
297
315
|
const video = pathname.split('/')[3];
|
|
298
316
|
const html = await app.renderAsync('partials/link-preview/tiktok', { video });
|
|
299
|
-
$anchor.replaceWith(html);
|
|
300
317
|
|
|
301
|
-
|
|
318
|
+
if ($anchor) {
|
|
319
|
+
$anchor.replaceWith(html);
|
|
320
|
+
return true;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return html;
|
|
302
324
|
}
|
|
303
325
|
|
|
304
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",
|