nodebb-plugin-mentions 4.6.0 → 4.6.1
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 +29 -24
- package/package.json +1 -1
package/library.js
CHANGED
|
@@ -37,6 +37,7 @@ const parts = {
|
|
|
37
37
|
};
|
|
38
38
|
const regex = RegExp(`${parts.before}${parts.main}`, 'gu');
|
|
39
39
|
const isLatinMention = /@[\w\d\-_.@]+$/;
|
|
40
|
+
const hasAnchors = /<a.*>.*<\/a>/i;
|
|
40
41
|
|
|
41
42
|
const Mentions = module.exports;
|
|
42
43
|
|
|
@@ -356,31 +357,35 @@ async function getMatches(content, isMarkdown = false) {
|
|
|
356
357
|
}
|
|
357
358
|
});
|
|
358
359
|
|
|
359
|
-
const
|
|
360
|
-
const
|
|
361
|
-
const urls = new Set();
|
|
362
|
-
Array.from(anchors).forEach((anchor) => {
|
|
363
|
-
const text = $(anchor).prop('innerText');
|
|
364
|
-
const match = text.match(regex);
|
|
365
|
-
if (match) {
|
|
366
|
-
urls.add($(anchor).attr('href'));
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
// Filter out urls that don't backreference to a remote id
|
|
371
|
-
const backrefs = await db.getObjectFields('remoteUrl:uid', Array.from(urls));
|
|
372
|
-
const urlAsIdExists = await db.isSortedSetMembers('usersRemote:lastCrawled', Array.from(urls));
|
|
360
|
+
const joined = splitContent.join('');
|
|
361
|
+
const parseAnchors = joined.match(hasAnchors);
|
|
373
362
|
const urlMap = new Map();
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
363
|
+
if (!isMarkdown && parseAnchors) {
|
|
364
|
+
const $ = cheerio.load(splitContent.join(''));
|
|
365
|
+
const anchors = $('a');
|
|
366
|
+
const urls = new Set();
|
|
367
|
+
Array.from(anchors).forEach((anchor) => {
|
|
368
|
+
const text = $(anchor).prop('innerText');
|
|
369
|
+
const match = text.match(regex);
|
|
370
|
+
if (match) {
|
|
371
|
+
urls.add($(anchor).attr('href'));
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
// Filter out urls that don't backreference to a remote id
|
|
376
|
+
const backrefs = await db.getObjectFields('remoteUrl:uid', Array.from(urls));
|
|
377
|
+
const urlAsIdExists = await db.isSortedSetMembers('usersRemote:lastCrawled', Array.from(urls));
|
|
378
|
+
Array.from(urls).map(async (url, index) => {
|
|
379
|
+
if (backrefs[url] || urlAsIdExists[index]) {
|
|
380
|
+
urlMap.set(url, backrefs[url] || url);
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
let slugs = await User.getUsersFields(Array.from(urlMap.values()), ['userslug']);
|
|
384
|
+
slugs = slugs.map(({ userslug }) => userslug);
|
|
385
|
+
Array.from(urlMap.keys()).forEach((url, idx) => {
|
|
386
|
+
urlMap.set(url, `/user/${encodeURIComponent(slugs[idx])}`);
|
|
387
|
+
});
|
|
388
|
+
}
|
|
384
389
|
|
|
385
390
|
return { splitContent, matches, urlMap };
|
|
386
391
|
}
|
package/package.json
CHANGED