@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.
@@ -433,7 +433,7 @@ var addLineBreakBeforePostLink = (el, forApp, isInline) => {
433
433
  el.parentNode.insertBefore(br, el);
434
434
  }
435
435
  };
436
- function a(el, forApp, parentDomain = "ecency.com", seoContext) {
436
+ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
437
437
  if (!el || !el.parentNode) {
438
438
  return;
439
439
  }
@@ -442,7 +442,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
442
442
  return;
443
443
  }
444
444
  const className = el.getAttribute("class");
445
- if (["markdown-author-link", "markdown-tag-link"].indexOf(className) !== -1) {
445
+ if (className && (["markdown-author-link", "markdown-tag-link"].includes(className) || className.includes("er-author") || className.includes("er-tag"))) {
446
446
  return;
447
447
  }
448
448
  if (href && href.trim().toLowerCase().startsWith("javascript:")) {
@@ -782,14 +782,29 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
782
782
  if (startTime) {
783
783
  el.setAttribute("data-start-time", startTime);
784
784
  }
785
- const thumbImg = el.ownerDocument.createElement("img");
786
- thumbImg.setAttribute("class", "no-replace video-thumbnail");
787
- thumbImg.setAttribute("itemprop", "thumbnailUrl");
788
- thumbImg.setAttribute("src", thumbnail);
789
- const play = el.ownerDocument.createElement("span");
790
- play.setAttribute("class", "markdown-video-play");
791
- el.appendChild(thumbImg);
792
- el.appendChild(play);
785
+ if (renderOptions?.embedVideosDirectly) {
786
+ const wrapper = el.ownerDocument.createElement("span");
787
+ wrapper.setAttribute("class", "er-youtube-frame");
788
+ wrapper.setAttribute("style", "display:block");
789
+ const iframe2 = el.ownerDocument.createElement("iframe");
790
+ iframe2.setAttribute("class", "youtube-player");
791
+ iframe2.setAttribute("src", embedSrc);
792
+ iframe2.setAttribute("title", "YouTube video");
793
+ iframe2.setAttribute("allow", "accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; web-share");
794
+ iframe2.setAttribute("allowfullscreen", "");
795
+ wrapper.appendChild(iframe2);
796
+ el.appendChild(wrapper);
797
+ el.setAttribute("class", "markdown-video-link markdown-video-link-youtube er-youtube");
798
+ } else {
799
+ const thumbImg = el.ownerDocument.createElement("img");
800
+ thumbImg.setAttribute("class", "no-replace video-thumbnail");
801
+ thumbImg.setAttribute("itemprop", "thumbnailUrl");
802
+ thumbImg.setAttribute("src", thumbnail);
803
+ const play = el.ownerDocument.createElement("span");
804
+ play.setAttribute("class", "markdown-video-play");
805
+ el.appendChild(thumbImg);
806
+ el.appendChild(play);
807
+ }
793
808
  return;
794
809
  }
795
810
  match = href.match(VIMEO_REGEX);
@@ -911,21 +926,36 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
911
926
  if (el.textContent.trim() === href) {
912
927
  el.textContent = "";
913
928
  }
914
- if (imgEls2.length === 1) {
915
- const src = imgEls2[0].getAttribute("src");
916
- if (src) {
917
- const thumbnail = proxifyImageSrc(src.replace(/\s+/g, ""), 0, 0, "match");
918
- const thumbImg = el.ownerDocument.createElement("img");
919
- thumbImg.setAttribute("class", "no-replace video-thumbnail");
920
- thumbImg.setAttribute("itemprop", "thumbnailUrl");
921
- thumbImg.setAttribute("src", thumbnail);
922
- el.appendChild(thumbImg);
923
- el.removeChild(imgEls2[0]);
929
+ if (renderOptions?.embedVideosDirectly) {
930
+ const wrapper = el.ownerDocument.createElement("span");
931
+ wrapper.setAttribute("class", "er-speak-frame");
932
+ wrapper.setAttribute("style", "display:block");
933
+ const iframe2 = el.ownerDocument.createElement("iframe");
934
+ iframe2.setAttribute("class", "speak-iframe");
935
+ iframe2.setAttribute("src", videoHref);
936
+ iframe2.setAttribute("title", "3Speak video");
937
+ iframe2.setAttribute("allow", "accelerometer; encrypted-media; gyroscope; picture-in-picture; web-share");
938
+ iframe2.setAttribute("allowfullscreen", "");
939
+ wrapper.appendChild(iframe2);
940
+ el.appendChild(wrapper);
941
+ el.setAttribute("class", "markdown-video-link markdown-video-link-speak er-speak");
942
+ } else {
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]);
953
+ }
924
954
  }
955
+ const play = el.ownerDocument.createElement("span");
956
+ play.setAttribute("class", "markdown-video-play");
957
+ el.appendChild(play);
925
958
  }
926
- const play = el.ownerDocument.createElement("span");
927
- play.setAttribute("class", "markdown-video-play");
928
- el.appendChild(play);
929
959
  return;
930
960
  }
931
961
  }
@@ -1015,7 +1045,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext) {
1015
1045
  }
1016
1046
 
1017
1047
  // src/methods/iframe.method.ts
1018
- function iframe(el, parentDomain = "ecency.com") {
1048
+ function iframe(el, parentDomain = "ecency.com", forApp = false) {
1019
1049
  if (!el || !el.parentNode) {
1020
1050
  return;
1021
1051
  }
@@ -1059,7 +1089,10 @@ function iframe(el, parentDomain = "ecency.com") {
1059
1089
  normalizedSrc = `${normalizedSrc}&mode=iframe`;
1060
1090
  }
1061
1091
  const hasAutoplay = /[?&]autoplay=/.test(normalizedSrc);
1062
- const s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1092
+ let s = hasAutoplay ? normalizedSrc : `${normalizedSrc}&autoplay=true`;
1093
+ if (forApp && !/[?&]layout=/.test(s)) {
1094
+ s = `${s}&layout=mobile`;
1095
+ }
1063
1096
  el.setAttribute("src", s);
1064
1097
  el.setAttribute("class", "speak-iframe");
1065
1098
  return;
@@ -1184,15 +1217,17 @@ function p(el) {
1184
1217
  }
1185
1218
 
1186
1219
  // src/methods/linkify.method.ts
1187
- function linkify(content, forApp) {
1220
+ function linkify(content, forApp, renderOptions) {
1188
1221
  content = content.replace(/(^|\s|>)(#[-a-z\d]+)/gi, (tag) => {
1189
1222
  if (/#[\d]+$/.test(tag)) return tag;
1190
1223
  const preceding = /^\s|>/.test(tag) ? tag[0] : "";
1191
1224
  tag = tag.replace(">", "");
1192
1225
  const tag2 = tag.trim().substring(1);
1193
1226
  const tagLower = tag2.toLowerCase();
1194
- const attrs = forApp ? `data-tag="${tagLower}"` : `href="/trending/${tagLower}"`;
1195
- return `${preceding}<a class="markdown-tag-link" ${attrs}>${tag.trim()}</a>`;
1227
+ if (!forApp) {
1228
+ return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
1229
+ }
1230
+ return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
1196
1231
  });
1197
1232
  content = content.replace(
1198
1233
  /(^|[^a-zA-Z0-9_!#$%&*@@/]|(^|[^a-zA-Z0-9_+~.-/]))[@@]([a-z][-.a-z\d^/]+[a-z\d])/gi,
@@ -1200,8 +1235,11 @@ function linkify(content, forApp) {
1200
1235
  const userLower = user.toLowerCase();
1201
1236
  const preceedings = (preceeding1 || "") + (preceeding2 || "");
1202
1237
  if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
1203
- const attrs = forApp ? `data-author="${userLower}"` : `href="/@${userLower}"`;
1204
- return `${preceedings}<a class="markdown-author-link" ${attrs}>@${user}</a>`;
1238
+ if (!forApp) {
1239
+ const avatarSrc = `https://images.ecency.com/u/${userLower}/avatar/small`;
1240
+ 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>`;
1241
+ }
1242
+ return `${preceedings}<a class="markdown-author-link" data-author="${userLower}">@${user}</a>`;
1205
1243
  } else {
1206
1244
  return match;
1207
1245
  }
@@ -1258,7 +1296,7 @@ function hasAncestor(node, tagNames) {
1258
1296
  }
1259
1297
  return false;
1260
1298
  }
1261
- function text(node, forApp) {
1299
+ function text(node, forApp, renderOptions) {
1262
1300
  if (!node || !node.parentNode) {
1263
1301
  return;
1264
1302
  }
@@ -1339,7 +1377,7 @@ function text(node, forApp) {
1339
1377
  }
1340
1378
 
1341
1379
  // src/methods/traverse.method.ts
1342
- function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext) {
1380
+ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, parentDomain = "ecency.com", seoContext, renderOptions) {
1343
1381
  if (!node || !node.childNodes) {
1344
1382
  return;
1345
1383
  }
@@ -1348,10 +1386,10 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1348
1386
  const next = child.nextSibling;
1349
1387
  const prev = child.previousSibling;
1350
1388
  if (child.nodeName.toLowerCase() === "a") {
1351
- a(child, forApp, parentDomain, seoContext);
1389
+ a(child, forApp, parentDomain, seoContext, renderOptions);
1352
1390
  }
1353
1391
  if (child.nodeName.toLowerCase() === "iframe") {
1354
- iframe(child, parentDomain);
1392
+ iframe(child, parentDomain, forApp);
1355
1393
  }
1356
1394
  if (child.nodeName === "#text") {
1357
1395
  text(child, forApp);
@@ -1363,11 +1401,11 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1363
1401
  p(child);
1364
1402
  }
1365
1403
  if (child.parentNode) {
1366
- traverse(child, forApp, depth + 1, state, parentDomain, seoContext);
1404
+ traverse(child, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
1367
1405
  } else {
1368
1406
  const possibleReplacement = next ? next.previousSibling : node.lastChild;
1369
1407
  if (possibleReplacement && possibleReplacement !== prev && possibleReplacement.parentNode === node) {
1370
- traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext);
1408
+ traverse(possibleReplacement, forApp, depth + 1, state, parentDomain, seoContext, renderOptions);
1371
1409
  }
1372
1410
  }
1373
1411
  child = next;
@@ -1420,7 +1458,7 @@ function fixBlockLevelTagsInParagraphs(html) {
1420
1458
  html = html.replace(/<p><br>\s*<\/p>/g, "");
1421
1459
  return html;
1422
1460
  }
1423
- function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext) {
1461
+ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
1424
1462
  input = input.replace(new RegExp("https://leofinance.io/threads/view/", "g"), "/@");
1425
1463
  input = input.replace(new RegExp("https://leofinance.io/posts/", "g"), "/@");
1426
1464
  input = input.replace(new RegExp("https://leofinance.io/threads/", "g"), "/@");
@@ -1480,7 +1518,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
1480
1518
  output = md.render(input);
1481
1519
  output = fixBlockLevelTagsInParagraphs(output);
1482
1520
  const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(output)}</body>`, "text/html");
1483
- traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
1521
+ traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
1484
1522
  output = serializer.serializeToString(doc);
1485
1523
  } catch (error) {
1486
1524
  try {
@@ -1493,7 +1531,7 @@ function markdownToHTML(input, forApp, parentDomain = "ecency.com", seoContext)
1493
1531
  });
1494
1532
  const repairedHtml = domSerializer(dom.children);
1495
1533
  const doc = DOMParser.parseFromString(`<body id="root">${removeDuplicateAttributes(repairedHtml)}</body>`, "text/html");
1496
- traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext);
1534
+ traverse(doc, forApp, 0, { firstImageFound: false }, parentDomain, seoContext, renderOptions);
1497
1535
  output = serializer.serializeToString(doc);
1498
1536
  } catch (fallbackError) {
1499
1537
  const escapedContent = he2.encode(output || md.render(input));
@@ -1521,18 +1559,18 @@ function cacheSet(key, value) {
1521
1559
  }
1522
1560
 
1523
1561
  // src/markdown-2-html.ts
1524
- function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext) {
1562
+ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency.com", seoContext, renderOptions) {
1525
1563
  if (typeof obj === "string") {
1526
1564
  const cleanedStr = cleanReply(obj);
1527
- return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext);
1565
+ return markdownToHTML(cleanedStr, forApp, parentDomain, seoContext, renderOptions);
1528
1566
  }
1529
- const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}`;
1567
+ const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
1530
1568
  const item = cacheGet(key);
1531
1569
  if (item) {
1532
1570
  return item;
1533
1571
  }
1534
1572
  const cleanBody = cleanReply(obj.body);
1535
- const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext);
1573
+ const res = markdownToHTML(cleanBody, forApp, parentDomain, seoContext, renderOptions);
1536
1574
  cacheSet(key, res);
1537
1575
  return res;
1538
1576
  }