@ecency/render-helper 2.4.14 → 2.4.15
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/dist/browser/index.d.ts +15 -2
- package/dist/browser/index.js +20 -12
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +20 -12
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +20 -12
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -420,6 +420,14 @@ function createImageHTML(src, isLCP, webp) {
|
|
|
420
420
|
}
|
|
421
421
|
|
|
422
422
|
// src/methods/a.method.ts
|
|
423
|
+
var NOFOLLOW_REPUTATION_THRESHOLD = 40;
|
|
424
|
+
var FOLLOW_PAYOUT_THRESHOLD = 5;
|
|
425
|
+
function getExternalLinkRel(seoContext) {
|
|
426
|
+
if (seoContext?.authorReputation !== void 0 && seoContext?.postPayout !== void 0 && seoContext.authorReputation >= NOFOLLOW_REPUTATION_THRESHOLD && seoContext.postPayout > FOLLOW_PAYOUT_THRESHOLD) {
|
|
427
|
+
return "noopener";
|
|
428
|
+
}
|
|
429
|
+
return "nofollow ugc noopener";
|
|
430
|
+
}
|
|
423
431
|
var normalizeValue = (value) => value ? value.trim() : "";
|
|
424
432
|
var matchesHref = (href, value) => {
|
|
425
433
|
const normalizedHref = normalizeValue(href);
|
|
@@ -453,7 +461,7 @@ var addLineBreakBeforePostLink = (el, forApp, isInline) => {
|
|
|
453
461
|
el.parentNode.insertBefore(br, el);
|
|
454
462
|
}
|
|
455
463
|
};
|
|
456
|
-
function a(el, forApp, webp, parentDomain = "ecency.com") {
|
|
464
|
+
function a(el, forApp, webp, parentDomain = "ecency.com", seoContext) {
|
|
457
465
|
if (!el || !el.parentNode) {
|
|
458
466
|
return;
|
|
459
467
|
}
|
|
@@ -1013,7 +1021,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1013
1021
|
el.setAttribute("class", "markdown-internal-link");
|
|
1014
1022
|
} else {
|
|
1015
1023
|
el.setAttribute("target", "_blank");
|
|
1016
|
-
el.setAttribute("rel",
|
|
1024
|
+
el.setAttribute("rel", getExternalLinkRel(seoContext));
|
|
1017
1025
|
}
|
|
1018
1026
|
el.setAttribute("href", href);
|
|
1019
1027
|
}
|
|
@@ -1302,7 +1310,7 @@ function text(node, forApp, webp) {
|
|
|
1302
1310
|
}
|
|
1303
1311
|
|
|
1304
1312
|
// src/methods/traverse.method.ts
|
|
1305
|
-
function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFound: false }, parentDomain = "ecency.com") {
|
|
1313
|
+
function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext) {
|
|
1306
1314
|
if (!node || !node.childNodes) {
|
|
1307
1315
|
return;
|
|
1308
1316
|
}
|
|
@@ -1310,7 +1318,7 @@ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFou
|
|
|
1310
1318
|
const child = node.childNodes[i];
|
|
1311
1319
|
if (!child) return;
|
|
1312
1320
|
if (child.nodeName.toLowerCase() === "a") {
|
|
1313
|
-
a(child, forApp, webp, parentDomain);
|
|
1321
|
+
a(child, forApp, webp, parentDomain, seoContext);
|
|
1314
1322
|
}
|
|
1315
1323
|
if (child.nodeName.toLowerCase() === "iframe") {
|
|
1316
1324
|
iframe(child, parentDomain);
|
|
@@ -1326,7 +1334,7 @@ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFou
|
|
|
1326
1334
|
}
|
|
1327
1335
|
const currentChild = node.childNodes[i];
|
|
1328
1336
|
if (currentChild) {
|
|
1329
|
-
traverse(currentChild, forApp, depth + 1, webp, state, parentDomain);
|
|
1337
|
+
traverse(currentChild, forApp, depth + 1, webp, state, parentDomain, seoContext);
|
|
1330
1338
|
}
|
|
1331
1339
|
});
|
|
1332
1340
|
}
|
|
@@ -1377,7 +1385,7 @@ function fixBlockLevelTagsInParagraphs(html) {
|
|
|
1377
1385
|
html = html.replace(/<p><br>\s*<\/p>/g, "");
|
|
1378
1386
|
return html;
|
|
1379
1387
|
}
|
|
1380
|
-
function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
1388
|
+
function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com", seoContext) {
|
|
1381
1389
|
input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
|
|
1382
1390
|
input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
|
|
1383
1391
|
input = input.replace(new RegExp("https://leofinance.io/threads/", "g"), "/@");
|
|
@@ -1437,7 +1445,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1437
1445
|
output = md.render(input);
|
|
1438
1446
|
output = fixBlockLevelTagsInParagraphs(output);
|
|
1439
1447
|
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
|
|
1440
|
-
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1448
|
+
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain, seoContext);
|
|
1441
1449
|
output = serializer.serializeToString(doc);
|
|
1442
1450
|
} catch (error) {
|
|
1443
1451
|
try {
|
|
@@ -1450,7 +1458,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
|
|
|
1450
1458
|
});
|
|
1451
1459
|
const repairedHtml = domSerializer(dom.children);
|
|
1452
1460
|
const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
|
|
1453
|
-
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
|
|
1461
|
+
traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain, seoContext);
|
|
1454
1462
|
output = serializer.serializeToString(doc);
|
|
1455
1463
|
} catch (fallbackError) {
|
|
1456
1464
|
const escapedContent = he2__default.default.encode(output || md.render(input));
|
|
@@ -1478,18 +1486,18 @@ function cacheSet(key, value) {
|
|
|
1478
1486
|
}
|
|
1479
1487
|
|
|
1480
1488
|
// src/markdown-2-html.ts
|
|
1481
|
-
function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.com") {
|
|
1489
|
+
function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.com", seoContext) {
|
|
1482
1490
|
if (typeof obj === "string") {
|
|
1483
1491
|
const cleanedStr = cleanReply(obj);
|
|
1484
|
-
return markdownToHTML(cleanedStr, forApp, webp, parentDomain);
|
|
1492
|
+
return markdownToHTML(cleanedStr, forApp, webp, parentDomain, seoContext);
|
|
1485
1493
|
}
|
|
1486
|
-
const key = `${makeEntryCacheKey(obj)}-md${webp ? "-webp" : ""}-${forApp ? "app" : "site"}-${parentDomain}`;
|
|
1494
|
+
const key = `${makeEntryCacheKey(obj)}-md${webp ? "-webp" : ""}-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}`;
|
|
1487
1495
|
const item = cacheGet(key);
|
|
1488
1496
|
if (item) {
|
|
1489
1497
|
return item;
|
|
1490
1498
|
}
|
|
1491
1499
|
const cleanBody = cleanReply(obj.body);
|
|
1492
|
-
const res = markdownToHTML(cleanBody, forApp, webp, parentDomain);
|
|
1500
|
+
const res = markdownToHTML(cleanBody, forApp, webp, parentDomain, seoContext);
|
|
1493
1501
|
cacheSet(key, res);
|
|
1494
1502
|
return res;
|
|
1495
1503
|
}
|