@ecency/render-helper 2.5.24 → 2.5.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.
@@ -1097,9 +1097,9 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
1097
1097
  if (el.textContent === href) {
1098
1098
  el.textContent = `@${author}/${section}`;
1099
1099
  }
1100
- if (forApp) {
1101
- const ha = `https://ecency.com/@${author}/${section}`;
1102
- el.setAttribute("href", ha);
1100
+ const external1 = renderOptions?.externalProfileBase;
1101
+ if (forApp || external1) {
1102
+ el.setAttribute("href", `${external1 ?? "https://ecency.com"}/@${author}/${section}`);
1103
1103
  } else {
1104
1104
  const h = `/@${author}/${section}`;
1105
1105
  el.setAttribute("href", h);
@@ -1167,9 +1167,9 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
1167
1167
  if (el.textContent === href) {
1168
1168
  el.textContent = `@${author}/${section}`;
1169
1169
  }
1170
- if (forApp) {
1171
- const ha = `https://ecency.com/@${author}/${section}`;
1172
- el.setAttribute("href", ha);
1170
+ const external2 = renderOptions?.externalProfileBase;
1171
+ if (forApp || external2) {
1172
+ el.setAttribute("href", `${external2 ?? "https://ecency.com"}/@${author}/${section}`);
1173
1173
  } else {
1174
1174
  const h = `/@${author}/${section}`;
1175
1175
  el.setAttribute("href", h);
@@ -1791,6 +1791,9 @@ function linkify(content, forApp, renderOptions) {
1791
1791
  const tag2 = tag.trim().substring(1);
1792
1792
  const tagLower = tag2.toLowerCase();
1793
1793
  if (!forApp) {
1794
+ if (renderOptions?.inertAuthorAndTagChips) {
1795
+ return `${preceding}<span class="er-tag er-tag-link">${tag.trim()}</span>`;
1796
+ }
1794
1797
  return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
1795
1798
  }
1796
1799
  return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
@@ -1804,7 +1807,8 @@ function linkify(content, forApp, renderOptions) {
1804
1807
  if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
1805
1808
  if (!forApp) {
1806
1809
  const avatarSrc = `${getProxyBase()}/u/${userLower}/avatar/small`;
1807
- const html = `${preceedings}<a class="er-author er-author-link" href="/@${userLower}"><img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/>@${userLower}</a>`;
1810
+ const inner = `<img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/>@${userLower}`;
1811
+ const html = renderOptions?.inertAuthorAndTagChips ? `${preceedings}<span class="er-author er-author-link">${inner}</span>` : `${preceedings}<a class="er-author er-author-link" href="/@${userLower}">${inner}</a>`;
1808
1812
  const placeholder = `\u200C${authorPlaceholders.length}\u200C`;
1809
1813
  authorPlaceholders.push({ placeholder, html });
1810
1814
  return placeholder;
@@ -1823,7 +1827,8 @@ function linkify(content, forApp, renderOptions) {
1823
1827
  const permlink = sanitizePermlink(p3);
1824
1828
  if (!isValidPermlink(permlink)) return match;
1825
1829
  if (SECTION_LIST.includes(permlink)) {
1826
- const attrs = forApp ? `href="https://ecency.com/@${authorLower}/${permlink}"` : `href="/@${authorLower}/${permlink}"`;
1830
+ const external = renderOptions?.externalProfileBase;
1831
+ const attrs = forApp || external ? `href="${external ?? "https://ecency.com"}/@${authorLower}/${permlink}"` : `href="/@${authorLower}/${permlink}"`;
1827
1832
  return `${preceding}<a class="markdown-profile-link" ${attrs}>@${authorLower}/${permlink}</a>`;
1828
1833
  } else {
1829
1834
  const attrs = forApp ? `data-author="${authorLower}" data-tag="${tag}" data-permlink="${permlink}"` : `href="/@${authorLower}/${permlink}"`;
@@ -1838,7 +1843,8 @@ function linkify(content, forApp, renderOptions) {
1838
1843
  const permlink = sanitizePermlink(p3);
1839
1844
  if (!isValidPermlink(permlink)) return match;
1840
1845
  if (SECTION_LIST.includes(permlink)) {
1841
- const attrs = forApp ? `href="https://ecency.com/@${uu}/${permlink}"` : `href="/@${uu}/${permlink}"`;
1846
+ const external = renderOptions?.externalProfileBase;
1847
+ const attrs = forApp || external ? `href="${external ?? "https://ecency.com"}/@${uu}/${permlink}"` : `href="/@${uu}/${permlink}"`;
1842
1848
  return ` <a class="markdown-profile-link" ${attrs}>@${uu}/${permlink}</a>`;
1843
1849
  } else {
1844
1850
  const attrs = forApp ? `data-author="${uu}" data-tag="post" data-permlink="${permlink}"` : `href="/@${uu}/${permlink}"`;
@@ -1869,6 +1875,19 @@ function hasAncestor(node, tagNames) {
1869
1875
  }
1870
1876
  return false;
1871
1877
  }
1878
+ var CHIP_CLASSES = ["er-author-link", "er-tag-link"];
1879
+ function hasChipAncestor(node) {
1880
+ let current = node.parentNode;
1881
+ while (current) {
1882
+ const el = current;
1883
+ const className = typeof el.getAttribute === "function" ? el.getAttribute("class") : null;
1884
+ if (className && className.split(/\s+/).some((token) => CHIP_CLASSES.includes(token))) {
1885
+ return true;
1886
+ }
1887
+ current = current.parentNode;
1888
+ }
1889
+ return false;
1890
+ }
1872
1891
  function text(node, forApp, renderOptions) {
1873
1892
  if (!node || !node.parentNode) {
1874
1893
  return;
@@ -1876,8 +1895,11 @@ function text(node, forApp, renderOptions) {
1876
1895
  if (hasAncestor(node, ["a", "code", "pre"])) {
1877
1896
  return;
1878
1897
  }
1898
+ if (renderOptions?.inertAuthorAndTagChips && hasChipAncestor(node)) {
1899
+ return;
1900
+ }
1879
1901
  const nodeValue = node.nodeValue || "";
1880
- const linkified = linkify(nodeValue, forApp);
1902
+ const linkified = linkify(nodeValue, forApp, renderOptions);
1881
1903
  if (linkified !== nodeValue) {
1882
1904
  const doc = DOMParser.parseFromString(
1883
1905
  `<span class="wr">${linkified}</span>`,
@@ -1965,7 +1987,7 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
1965
1987
  iframe(child, parentDomain, forApp, renderOptions);
1966
1988
  }
1967
1989
  if (child.nodeName === "#text") {
1968
- text(child, forApp);
1990
+ text(child, forApp, renderOptions);
1969
1991
  }
1970
1992
  if (child.nodeName.toLowerCase() === "img") {
1971
1993
  img(child, state, forApp);
@@ -2169,7 +2191,7 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
2169
2191
  logIfSlow(performance.now() - t02, `body_len=${obj.length}`);
2170
2192
  return res2;
2171
2193
  }
2172
- const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
2194
+ const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}${renderOptions?.inertAuthorAndTagChips ? "-inert" : ""}${renderOptions?.externalProfileBase ? "-ext" + renderOptions.externalProfileBase : ""}`;
2173
2195
  const item = cacheGet(key);
2174
2196
  if (item) {
2175
2197
  return item;