@ecency/render-helper 2.5.23 → 2.5.25
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 +12 -1
- package/dist/browser/index.js +66 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +66 -10
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +66 -11
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -601,6 +601,40 @@ function isValidUrl(url) {
|
|
|
601
601
|
return false;
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
|
+
var MAX_PROXIED_URL_LENGTH = 2048;
|
|
605
|
+
var LEGACY_SIZED_PROXY_RE = /^https:\/\/(?:images\.hive\.blog|steemitimages\.com)\/\d+x\d+\/(.+)$/;
|
|
606
|
+
function isLegacySizedProxyUrl(url) {
|
|
607
|
+
if (!url || typeof url !== "string") return false;
|
|
608
|
+
return LEGACY_SIZED_PROXY_RE.test(url);
|
|
609
|
+
}
|
|
610
|
+
function extractLegacySizedSource(url) {
|
|
611
|
+
const m = LEGACY_SIZED_PROXY_RE.exec(url);
|
|
612
|
+
if (!m) return null;
|
|
613
|
+
const rest = m[1];
|
|
614
|
+
const hashIndex = rest.indexOf("#");
|
|
615
|
+
const addressable = hashIndex >= 0 ? rest.slice(0, hashIndex) : rest;
|
|
616
|
+
const qIndex = addressable.indexOf("?");
|
|
617
|
+
const path = qIndex >= 0 ? addressable.slice(0, qIndex) : addressable;
|
|
618
|
+
const query = qIndex >= 0 ? addressable.slice(qIndex + 1) : "";
|
|
619
|
+
let end = path.length;
|
|
620
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) {
|
|
621
|
+
end--;
|
|
622
|
+
}
|
|
623
|
+
try {
|
|
624
|
+
const inner = new URL(path.slice(0, end));
|
|
625
|
+
if (query) {
|
|
626
|
+
for (const [key, value] of new URLSearchParams(query)) {
|
|
627
|
+
inner.searchParams.append(key, value);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
return inner.toString();
|
|
631
|
+
} catch {
|
|
632
|
+
return null;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
function isLegacyForeignProxyUrl(url) {
|
|
636
|
+
return url.indexOf("https://images.hive.blog/") === 0 && url.indexOf("https://images.hive.blog/D") !== 0 || url.indexOf("https://steemitimages.com/") === 0 && url.indexOf("https://steemitimages.com/D") !== 0;
|
|
637
|
+
}
|
|
604
638
|
function getLatestUrl(str) {
|
|
605
639
|
const [last] = [...str.replace(/https?:\/\//g, "\n$&").trim().split("\n")].reverse();
|
|
606
640
|
return last;
|
|
@@ -609,17 +643,17 @@ function proxifyForFormat(url, width = 0, height = 0, format = "match", opts = {
|
|
|
609
643
|
if (!url || typeof url !== "string" || !isValidUrl(url)) {
|
|
610
644
|
return "";
|
|
611
645
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
return url.replace("https://images.hive.blog", proxyBase);
|
|
646
|
+
if (url.length > MAX_PROXIED_URL_LENGTH) {
|
|
647
|
+
return "";
|
|
615
648
|
}
|
|
616
|
-
|
|
617
|
-
|
|
649
|
+
const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
|
|
650
|
+
if (isLegacyForeignProxyUrl(url) && !(isLegacySizedProxyUrl(url) && routeThroughProxy)) {
|
|
651
|
+
return url.replace("https://images.hive.blog", proxyBase).replace("https://steemitimages.com", proxyBase);
|
|
618
652
|
}
|
|
619
653
|
if (url.indexOf("https://images.ecency.com/") === 0 && !routeThroughProxy) {
|
|
620
654
|
return url.replace("https://images.ecency.com", proxyBase);
|
|
621
655
|
}
|
|
622
|
-
const realUrl = getLatestUrl(url);
|
|
656
|
+
const realUrl = extractLegacySizedSource(url) ?? getLatestUrl(url);
|
|
623
657
|
const pHash = extractPHash(realUrl);
|
|
624
658
|
const options = {
|
|
625
659
|
format,
|
|
@@ -679,6 +713,7 @@ function isPictureEligibleRawUrl(rawUrl) {
|
|
|
679
713
|
return false;
|
|
680
714
|
}
|
|
681
715
|
if (u.protocol !== "http:" && u.protocol !== "https:") return false;
|
|
716
|
+
if (isLegacySizedProxyUrl(rawUrl)) return true;
|
|
682
717
|
const host = `${u.protocol}//${u.host}`;
|
|
683
718
|
const isProxyHost = host === proxyBase || host === "https://images.ecency.com";
|
|
684
719
|
if (isProxyHost && (u.pathname.startsWith("/p/") || u.pathname.startsWith("/u/") || SIZED_PROXY_PATH.test(u.pathname))) {
|
|
@@ -1728,6 +1763,9 @@ function linkify(content, forApp, renderOptions) {
|
|
|
1728
1763
|
const tag2 = tag.trim().substring(1);
|
|
1729
1764
|
const tagLower = tag2.toLowerCase();
|
|
1730
1765
|
if (!forApp) {
|
|
1766
|
+
if (renderOptions?.inertAuthorAndTagChips) {
|
|
1767
|
+
return `${preceding}<span class="er-tag er-tag-link">${tag.trim()}</span>`;
|
|
1768
|
+
}
|
|
1731
1769
|
return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
|
|
1732
1770
|
}
|
|
1733
1771
|
return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
|
|
@@ -1741,7 +1779,8 @@ function linkify(content, forApp, renderOptions) {
|
|
|
1741
1779
|
if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
|
|
1742
1780
|
if (!forApp) {
|
|
1743
1781
|
const avatarSrc = `${getProxyBase()}/u/${userLower}/avatar/small`;
|
|
1744
|
-
const
|
|
1782
|
+
const inner = `<img class="er-author-link-image" src="${avatarSrc}" alt="${userLower}"/>@${userLower}`;
|
|
1783
|
+
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>`;
|
|
1745
1784
|
const placeholder = `\u200C${authorPlaceholders.length}\u200C`;
|
|
1746
1785
|
authorPlaceholders.push({ placeholder, html });
|
|
1747
1786
|
return placeholder;
|
|
@@ -1806,6 +1845,19 @@ function hasAncestor(node, tagNames) {
|
|
|
1806
1845
|
}
|
|
1807
1846
|
return false;
|
|
1808
1847
|
}
|
|
1848
|
+
var CHIP_CLASSES = ["er-author-link", "er-tag-link"];
|
|
1849
|
+
function hasChipAncestor(node) {
|
|
1850
|
+
let current = node.parentNode;
|
|
1851
|
+
while (current) {
|
|
1852
|
+
const el = current;
|
|
1853
|
+
const className = typeof el.getAttribute === "function" ? el.getAttribute("class") : null;
|
|
1854
|
+
if (className && className.split(/\s+/).some((token) => CHIP_CLASSES.includes(token))) {
|
|
1855
|
+
return true;
|
|
1856
|
+
}
|
|
1857
|
+
current = current.parentNode;
|
|
1858
|
+
}
|
|
1859
|
+
return false;
|
|
1860
|
+
}
|
|
1809
1861
|
function text(node, forApp, renderOptions) {
|
|
1810
1862
|
if (!node || !node.parentNode) {
|
|
1811
1863
|
return;
|
|
@@ -1813,8 +1865,11 @@ function text(node, forApp, renderOptions) {
|
|
|
1813
1865
|
if (hasAncestor(node, ["a", "code", "pre"])) {
|
|
1814
1866
|
return;
|
|
1815
1867
|
}
|
|
1868
|
+
if (renderOptions?.inertAuthorAndTagChips && hasChipAncestor(node)) {
|
|
1869
|
+
return;
|
|
1870
|
+
}
|
|
1816
1871
|
const nodeValue = node.nodeValue || "";
|
|
1817
|
-
const linkified = linkify(nodeValue, forApp);
|
|
1872
|
+
const linkified = linkify(nodeValue, forApp, renderOptions);
|
|
1818
1873
|
if (linkified !== nodeValue) {
|
|
1819
1874
|
const doc = DOMParser.parseFromString(
|
|
1820
1875
|
`<span class="wr">${linkified}</span>`,
|
|
@@ -1902,7 +1957,7 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
|
|
|
1902
1957
|
iframe(child, parentDomain, forApp, renderOptions);
|
|
1903
1958
|
}
|
|
1904
1959
|
if (child.nodeName === "#text") {
|
|
1905
|
-
text(child, forApp);
|
|
1960
|
+
text(child, forApp, renderOptions);
|
|
1906
1961
|
}
|
|
1907
1962
|
if (child.nodeName.toLowerCase() === "img") {
|
|
1908
1963
|
img(child, state, forApp);
|
|
@@ -2106,7 +2161,7 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
|
|
|
2106
2161
|
logIfSlow(performance.now() - t02, `body_len=${obj.length}`);
|
|
2107
2162
|
return res2;
|
|
2108
2163
|
}
|
|
2109
|
-
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
|
|
2164
|
+
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}${renderOptions?.inertAuthorAndTagChips ? "-inert" : ""}`;
|
|
2110
2165
|
const item = cacheGet(key);
|
|
2111
2166
|
if (item) {
|
|
2112
2167
|
return item;
|
|
@@ -2378,6 +2433,6 @@ function getPostBodySummary(obj, length, platform) {
|
|
|
2378
2433
|
return res;
|
|
2379
2434
|
}
|
|
2380
2435
|
|
|
2381
|
-
export { IMAGE_SIZES, SECTION_LIST, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
|
|
2436
|
+
export { IMAGE_SIZES, SECTION_LIST, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isLegacySizedProxyUrl, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
|
|
2382
2437
|
//# sourceMappingURL=index.mjs.map
|
|
2383
2438
|
//# sourceMappingURL=index.mjs.map
|