@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.
@@ -391,6 +391,14 @@ function createImageHTML(src, isLCP, webp) {
391
391
  }
392
392
 
393
393
  // src/methods/a.method.ts
394
+ var NOFOLLOW_REPUTATION_THRESHOLD = 40;
395
+ var FOLLOW_PAYOUT_THRESHOLD = 5;
396
+ function getExternalLinkRel(seoContext) {
397
+ if (seoContext?.authorReputation !== void 0 && seoContext?.postPayout !== void 0 && seoContext.authorReputation >= NOFOLLOW_REPUTATION_THRESHOLD && seoContext.postPayout > FOLLOW_PAYOUT_THRESHOLD) {
398
+ return "noopener";
399
+ }
400
+ return "nofollow ugc noopener";
401
+ }
394
402
  var normalizeValue = (value) => value ? value.trim() : "";
395
403
  var matchesHref = (href, value) => {
396
404
  const normalizedHref = normalizeValue(href);
@@ -424,7 +432,7 @@ var addLineBreakBeforePostLink = (el, forApp, isInline) => {
424
432
  el.parentNode.insertBefore(br, el);
425
433
  }
426
434
  };
427
- function a(el, forApp, webp, parentDomain = "ecency.com") {
435
+ function a(el, forApp, webp, parentDomain = "ecency.com", seoContext) {
428
436
  if (!el || !el.parentNode) {
429
437
  return;
430
438
  }
@@ -984,7 +992,7 @@ function a(el, forApp, webp, parentDomain = "ecency.com") {
984
992
  el.setAttribute("class", "markdown-internal-link");
985
993
  } else {
986
994
  el.setAttribute("target", "_blank");
987
- el.setAttribute("rel", "noopener");
995
+ el.setAttribute("rel", getExternalLinkRel(seoContext));
988
996
  }
989
997
  el.setAttribute("href", href);
990
998
  }
@@ -1273,7 +1281,7 @@ function text(node, forApp, webp) {
1273
1281
  }
1274
1282
 
1275
1283
  // src/methods/traverse.method.ts
1276
- function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFound: false }, parentDomain = "ecency.com") {
1284
+ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext) {
1277
1285
  if (!node || !node.childNodes) {
1278
1286
  return;
1279
1287
  }
@@ -1281,7 +1289,7 @@ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFou
1281
1289
  const child = node.childNodes[i];
1282
1290
  if (!child) return;
1283
1291
  if (child.nodeName.toLowerCase() === "a") {
1284
- a(child, forApp, webp, parentDomain);
1292
+ a(child, forApp, webp, parentDomain, seoContext);
1285
1293
  }
1286
1294
  if (child.nodeName.toLowerCase() === "iframe") {
1287
1295
  iframe(child, parentDomain);
@@ -1297,7 +1305,7 @@ function traverse(node, forApp, depth = 0, webp = false, state = { firstImageFou
1297
1305
  }
1298
1306
  const currentChild = node.childNodes[i];
1299
1307
  if (currentChild) {
1300
- traverse(currentChild, forApp, depth + 1, webp, state, parentDomain);
1308
+ traverse(currentChild, forApp, depth + 1, webp, state, parentDomain, seoContext);
1301
1309
  }
1302
1310
  });
1303
1311
  }
@@ -1348,7 +1356,7 @@ function fixBlockLevelTagsInParagraphs(html) {
1348
1356
  html = html.replace(/<p><br>\s*<\/p>/g, "");
1349
1357
  return html;
1350
1358
  }
1351
- function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1359
+ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com", seoContext) {
1352
1360
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1353
1361
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
1354
1362
  input = input.replace(new RegExp("https://leofinance.io/threads/", "g"), "/@");
@@ -1408,7 +1416,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1408
1416
  output = md.render(input);
1409
1417
  output = fixBlockLevelTagsInParagraphs(output);
1410
1418
  const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
1411
- traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1419
+ traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain, seoContext);
1412
1420
  output = serializer.serializeToString(doc);
1413
1421
  } catch (error) {
1414
1422
  try {
@@ -1421,7 +1429,7 @@ function markdownToHTML(input, forApp, webp, parentDomain = "ecency.com") {
1421
1429
  });
1422
1430
  const repairedHtml = domSerializer(dom.children);
1423
1431
  const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
1424
- traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain);
1432
+ traverse(doc, forApp, 0, webp, { firstImageFound: false }, parentDomain, seoContext);
1425
1433
  output = serializer.serializeToString(doc);
1426
1434
  } catch (fallbackError) {
1427
1435
  const escapedContent = he2.encode(output || md.render(input));
@@ -1449,18 +1457,18 @@ function cacheSet(key, value) {
1449
1457
  }
1450
1458
 
1451
1459
  // src/markdown-2-html.ts
1452
- function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.com") {
1460
+ function markdown2Html(obj, forApp = true, webp = false, parentDomain = "ecency.com", seoContext) {
1453
1461
  if (typeof obj === "string") {
1454
1462
  const cleanedStr = cleanReply(obj);
1455
- return markdownToHTML(cleanedStr, forApp, webp, parentDomain);
1463
+ return markdownToHTML(cleanedStr, forApp, webp, parentDomain, seoContext);
1456
1464
  }
1457
- const key = `${makeEntryCacheKey(obj)}-md${webp ? "-webp" : ""}-${forApp ? "app" : "site"}-${parentDomain}`;
1465
+ const key = `${makeEntryCacheKey(obj)}-md${webp ? "-webp" : ""}-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}`;
1458
1466
  const item = cacheGet(key);
1459
1467
  if (item) {
1460
1468
  return item;
1461
1469
  }
1462
1470
  const cleanBody = cleanReply(obj.body);
1463
- const res = markdownToHTML(cleanBody, forApp, webp, parentDomain);
1471
+ const res = markdownToHTML(cleanBody, forApp, webp, parentDomain, seoContext);
1464
1472
  cacheSet(key, res);
1465
1473
  return res;
1466
1474
  }