@ecency/render-helper 2.4.24 → 2.4.26

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.
@@ -462,7 +462,7 @@ var addLineBreakBeforePostLink = (el, forApp, isInline) => {
462
462
  el.parentNode.insertBefore(br, el);
463
463
  }
464
464
  };
465
- function a(el, forApp, parentDomain = "ecency.com", seoContext) {
465
+ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
466
466
  if (!el || !el.parentNode) {
467
467
  return;
468
468
  }
@@ -471,7 +471,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
471
471
  return;
472
472
  }
473
473
  const className = el.getAttribute("class");
474
- if (["markdown-author-link", "markdown-tag-link"].indexOf(className) !== -1) {
474
+ if (className && (["markdown-author-link", "markdown-tag-link"].includes(className) || className.includes("er-author") || className.includes("er-tag"))) {
475
475
  return;
476
476
  }
477
477
  if (href && href.trim().toLowerCase().startsWith("javascript:")) {
@@ -811,14 +811,29 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
811
811
  if (startTime) {
812
812
  el.setAttribute("data-start-time", startTime);
813
813
  }
814
- const thumbImg = el.ownerDocument.createElement("img");
815
- thumbImg.setAttribute("class", "no-replace video-thumbnail");
816
- thumbImg.setAttribute("itemprop", "thumbnailUrl");
817
- thumbImg.setAttribute("src", thumbnail);
818
- const play = el.ownerDocument.createElement("span");
819
- play.setAttribute("class", "markdown-video-play");
820
- el.appendChild(thumbImg);
821
- el.appendChild(play);
814
+ if (renderOptions?.embedVideosDirectly) {
815
+ const wrapper = el.ownerDocument.createElement("span");
816
+ wrapper.setAttribute("class", "er-youtube-frame");
817
+ wrapper.setAttribute("style", "display:block");
818
+ const iframe2 = el.ownerDocument.createElement("iframe");
819
+ iframe2.setAttribute("class", "youtube-player");
820
+ iframe2.setAttribute("src", embedSrc);
821
+ iframe2.setAttribute("title", "YouTube video");
822
+ iframe2.setAttribute("allow", "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; web-share");
823
+ iframe2.setAttribute("allowfullscreen", "");
824
+ wrapper.appendChild(iframe2);
825
+ el.appendChild(wrapper);
826
+ el.setAttribute("class", "markdown-video-link markdown-video-link-youtube er-youtube");
827
+ } else {
828
+ const thumbImg = el.ownerDocument.createElement("img");
829
+ thumbImg.setAttribute("class", "no-replace video-thumbnail");
830
+ thumbImg.setAttribute("itemprop", "thumbnailUrl");
831
+ thumbImg.setAttribute("src", thumbnail);
832
+ const play = el.ownerDocument.createElement("span");
833
+ play.setAttribute("class", "markdown-video-play");
834
+ el.appendChild(thumbImg);
835
+ el.appendChild(play);
836
+ }
822
837
  return;
823
838
  }
824
839
  match = href.match(VIMEO_REGEX);
@@ -940,21 +955,36 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
940
955
  if (el.textContent.trim() === href) {
941
956
  el.textContent = "";
942
957
  }
943
- if (imgEls2.length === 1) {
944
- const src = imgEls2[0].getAttribute("src");
945
- if (src) {
946
- const thumbnail = proxifyImageSrc(src.replace(/\s+/g, ""), 0, 0, "match");
947
- const thumbImg = el.ownerDocument.createElement("img");
948
- thumbImg.setAttribute("class", "no-replace video-thumbnail");
949
- thumbImg.setAttribute("itemprop", "thumbnailUrl");
950
- thumbImg.setAttribute("src", thumbnail);
951
- el.appendChild(thumbImg);
952
- el.removeChild(imgEls2[0]);
958
+ if (renderOptions?.embedVideosDirectly) {
959
+ const wrapper = el.ownerDocument.createElement("span");
960
+ wrapper.setAttribute("class", "er-speak-frame");
961
+ wrapper.setAttribute("style", "display:block");
962
+ const iframe2 = el.ownerDocument.createElement("iframe");
963
+ iframe2.setAttribute("class", "speak-iframe");
964
+ iframe2.setAttribute("src", videoHref);
965
+ iframe2.setAttribute("title", "3Speak video");
966
+ iframe2.setAttribute("allow", "accelerometer; encrypted-media; gyroscope; picture-in-picture; web-share");
967
+ iframe2.setAttribute("allowfullscreen", "");
968
+ wrapper.appendChild(iframe2);
969
+ el.appendChild(wrapper);
970
+ el.setAttribute("class", "markdown-video-link markdown-video-link-speak er-speak");
971
+ } else {
972
+ if (imgEls2.length === 1) {
973
+ const src = imgEls2[0].getAttribute("src");
974
+ if (src) {
975
+ const thumbnail = proxifyImageSrc(src.replace(/\s+/g, ""), 0, 0, "match");
976
+ const thumbImg = el.ownerDocument.createElement("img");
977
+ thumbImg.setAttribute("class", "no-replace video-thumbnail");
978
+ thumbImg.setAttribute("itemprop", "thumbnailUrl");
979
+ thumbImg.setAttribute("src", thumbnail);
980
+ el.appendChild(thumbImg);
981
+ el.removeChild(imgEls2[0]);
982
+ }
953
983
  }
984
+ const play = el.ownerDocument.createElement("span");
985
+ play.setAttribute("class", "markdown-video-play");
986
+ el.appendChild(play);
954
987
  }
955
- const play = el.ownerDocument.createElement("span");
956
- play.setAttribute("class", "markdown-video-play");
957
- el.appendChild(play);
958
988
  return;
959
989
  }
960
990
  }
@@ -1044,7 +1074,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
1044
1074
  }
1045
1075
 
1046
1076
  // src/methods/iframe.method.ts
1047
- function iframe(el, parentDomain = "ecency.com") {
1077
+ function iframe(el, parentDomain = "ecency.com", forApp = false) {
1048
1078
  if (!el || !el.parentNode) {
1049
1079
  return;
1050
1080
  }
@@ -1088,7 +1118,10 @@ function iframe(el, parentDomain = "ecency.com") {
1088
1118
  normalizedSrc = `${normalizedSrc}&mode=iframe`;
1089
1119
  }
1090
1120
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
1091
- const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1121
+ let s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1122
+ if (forApp && !/[?&]layout=/.test(s)) {
1123
+ s = `${s}&layout=mobile`;
1124
+ }
1092
1125
  el.setAttribute("src", s);
1093
1126
  el.setAttribute("class", "speak-iframe");
1094
1127
  return;
@@ -1213,15 +1246,17 @@ function p(el) {
1213
1246
  }
1214
1247
 
1215
1248
  // src/methods/linkify.method.ts
1216
- function linkify(content, forApp) {
1249
+ function linkify(content, forApp, renderOptions) {
1217
1250
  content = content.replace(/(^|\s|>)(#[-a-z\d]+)/gi, (tag) => {
1218
1251
  if (/#[\d]+$/.test(tag)) return tag;
1219
1252
  const preceding = /^\s|>/.test(tag) ? tag[0] : "";
1220
1253
  tag = tag.replace(">", "");
1221
1254
  const tag2 = tag.trim().substring(1);
1222
1255
  const tagLower = tag2.toLowerCase();
1223
- const attrs = forApp ? `data-tag="${tagLower}"` : `href="/trending/${tagLower}"`;
1224
- return `${preceding}<a class="markdown-tag-link" ${attrs}>${tag.trim()}</a>`;
1256
+ if (!forApp) {
1257
+ return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
1258
+ }
1259
+ return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
1225
1260
  });
1226
1261
  content = content.replace(
1227
1262
  /(^|[^a-zA-Z0-9_!#$%&*@@/]|(^|[^a-zA-Z0-9_+~.-/]))[@@]([a-z][-.a-z\d^/]+[a-z\d])/gi,
@@ -1229,8 +1264,11 @@ function linkify(content, forApp) {
1229
1264
  const userLower = user.toLowerCase();
1230
1265
  const preceedings = (preceeding1 || "") + (preceeding2 || "");
1231
1266
  if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
1232
- const attrs = forApp ? `data-author="${userLower}"` : `href="/@${userLower}"`;
1233
- return `${preceedings}<a class="markdown-author-link" ${attrs}>@${user}</a>`;
1267
+ if (!forApp) {
1268
+ const avatarSrc = `https://images.ecency.com/u/${userLower}/avatar/small`;
1269
+ return `${preceedings}<a class="er-author er-author-link" href="/@${userLower}"><img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/><span class="er-author-link-content"><span class="er-author-link-label">Hive account</span><span>@${userLower}</span></span></a>`;
1270
+ }
1271
+ return `${preceedings}<a class="markdown-author-link" data-author="${userLower}">@${user}</a>`;
1234
1272
  } else {
1235
1273
  return match;
1236
1274
  }
@@ -1287,7 +1325,7 @@ function hasAncestor(node, tagNames) {
1287
1325
  }
1288
1326
  return false;
1289
1327
  }
1290
- function text(node, forApp) {
1328
+ function text(node, forApp, renderOptions) {
1291
1329
  if (!node || !node.parentNode) {
1292
1330
  return;
1293
1331
  }
@@ -1368,7 +1406,7 @@ function text(node, forApp) {
1368
1406
  }
1369
1407
 
1370
1408
  // src/methods/traverse.method.ts
1371
- function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext) {
1409
+ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext, renderOptions) {
1372
1410
  if (!node || !node.childNodes) {
1373
1411
  return;
1374
1412
  }
@@ -1377,10 +1415,10 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1377
1415
  const next = child.nextSibling;
1378
1416
  const prev = child.previousSibling;
1379
1417
  if (child.nodeName.toLowerCase() === "a") {
1380
- a(child, forApp, parentDomain, seoContext);
1418
+ a(child, forApp, parentDomain, seoContext, renderOptions);
1381
1419
  }
1382
1420
  if (child.nodeName.toLowerCase() === "iframe") {
1383
- iframe(child, parentDomain);
1421
+ iframe(child, parentDomain, forApp);
1384
1422
  }
1385
1423
  if (child.nodeName === "#text") {
1386
1424
  text(child, forApp);
@@ -1392,11 +1430,11 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1392
1430
  p(child);
1393
1431
  }
1394
1432
  if (child.parentNode) {
1395
- traverse(child, forApp, depth + 1, state, parentDomain, seoContext);
1433
+ traverse(child, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
1396
1434
  } else {
1397
1435
  const possibleReplacement = next ? next.previousSibling : node.lastChild;
1398
1436
  if (possibleReplacement && possibleReplacement !== prev && possibleReplacement.parentNode === node) {
1399
- traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext);
1437
+ traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
1400
1438
  }
1401
1439
  }
1402
1440
  child = next;
@@ -1449,7 +1487,7 @@ function fixBlockLevelTagsInParagraphs(html) {
1449
1487
  html = html.replace(/<p><br>\s*<\/p>/g, "");
1450
1488
  return html;
1451
1489
  }
1452
- function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext) {
1490
+ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
1453
1491
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1454
1492
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
1455
1493
  input = input.replace(new RegExp("https://leofinance.io/threads/", "g"), "/@");
@@ -1509,7 +1547,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
1509
1547
  output = md.render(input);
1510
1548
  output = fixBlockLevelTagsInParagraphs(output);
1511
1549
  const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
1512
- traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
1550
+ traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
1513
1551
  output = serializer.serializeToString(doc);
1514
1552
  } catch (error) {
1515
1553
  try {
@@ -1522,7 +1560,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
1522
1560
  });
1523
1561
  const repairedHtml = domSerializer(dom.children);
1524
1562
  const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
1525
- traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
1563
+ traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
1526
1564
  output = serializer.serializeToString(doc);
1527
1565
  } catch (fallbackError) {
1528
1566
  const escapedContent = he2__default.default.encode(output || md.render(input));
@@ -1550,18 +1588,18 @@ function cacheSet(key, value) {
1550
1588
  }
1551
1589
 
1552
1590
  // src/markdown-2-html.ts
1553
- function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext) {
1591
+ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext, renderOptions) {
1554
1592
  if (typeof obj === "string") {
1555
1593
  const cleanedStr = cleanReply(obj);
1556
- return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext);
1594
+ return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext, renderOptions);
1557
1595
  }
1558
- const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}`;
1596
+ const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
1559
1597
  const item = cacheGet(key);
1560
1598
  if (item) {
1561
1599
  return item;
1562
1600
  }
1563
1601
  const cleanBody = cleanReply(obj.body);
1564
- const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext);
1602
+ const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext, renderOptions);
1565
1603
  cacheSet(key, res);
1566
1604
  return res;
1567
1605
  }