@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.cjs
CHANGED
|
@@ -629,6 +629,40 @@ function isValidUrl(url) {
|
|
|
629
629
|
return false;
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
|
+
var MAX_PROXIED_URL_LENGTH = 2048;
|
|
633
|
+
var LEGACY_SIZED_PROXY_RE = /^https:\/\/(?:images\.hive\.blog|steemitimages\.com)\/\d+x\d+\/(.+)$/;
|
|
634
|
+
function isLegacySizedProxyUrl(url) {
|
|
635
|
+
if (!url || typeof url !== "string") return false;
|
|
636
|
+
return LEGACY_SIZED_PROXY_RE.test(url);
|
|
637
|
+
}
|
|
638
|
+
function extractLegacySizedSource(url) {
|
|
639
|
+
const m = LEGACY_SIZED_PROXY_RE.exec(url);
|
|
640
|
+
if (!m) return null;
|
|
641
|
+
const rest = m[1];
|
|
642
|
+
const hashIndex = rest.indexOf("#");
|
|
643
|
+
const addressable = hashIndex >= 0 ? rest.slice(0, hashIndex) : rest;
|
|
644
|
+
const qIndex = addressable.indexOf("?");
|
|
645
|
+
const path = qIndex >= 0 ? addressable.slice(0, qIndex) : addressable;
|
|
646
|
+
const query = qIndex >= 0 ? addressable.slice(qIndex + 1) : "";
|
|
647
|
+
let end = path.length;
|
|
648
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) {
|
|
649
|
+
end--;
|
|
650
|
+
}
|
|
651
|
+
try {
|
|
652
|
+
const inner = new URL(path.slice(0, end));
|
|
653
|
+
if (query) {
|
|
654
|
+
for (const [key, value] of new URLSearchParams(query)) {
|
|
655
|
+
inner.searchParams.append(key, value);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return inner.toString();
|
|
659
|
+
} catch {
|
|
660
|
+
return null;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function isLegacyForeignProxyUrl(url) {
|
|
664
|
+
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;
|
|
665
|
+
}
|
|
632
666
|
function getLatestUrl(str) {
|
|
633
667
|
const [last] = [...str.replace(/https?:\/\//g, "\n$&").trim().split("\n")].reverse();
|
|
634
668
|
return last;
|
|
@@ -637,17 +671,17 @@ function proxifyForFormat(url, width = 0, height = 0, format = "match", opts = {
|
|
|
637
671
|
if (!url || typeof url !== "string" || !isValidUrl(url)) {
|
|
638
672
|
return "";
|
|
639
673
|
}
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
return url.replace("https://images.hive.blog", proxyBase);
|
|
674
|
+
if (url.length > MAX_PROXIED_URL_LENGTH) {
|
|
675
|
+
return "";
|
|
643
676
|
}
|
|
644
|
-
|
|
645
|
-
|
|
677
|
+
const routeThroughProxy = width > 0 || height > 0 || !!opts.blur || !!opts.forceProxy;
|
|
678
|
+
if (isLegacyForeignProxyUrl(url) && !(isLegacySizedProxyUrl(url) && routeThroughProxy)) {
|
|
679
|
+
return url.replace("https://images.hive.blog", proxyBase).replace("https://steemitimages.com", proxyBase);
|
|
646
680
|
}
|
|
647
681
|
if (url.indexOf("https://images.ecency.com/") === 0 && !routeThroughProxy) {
|
|
648
682
|
return url.replace("https://images.ecency.com", proxyBase);
|
|
649
683
|
}
|
|
650
|
-
const realUrl = getLatestUrl(url);
|
|
684
|
+
const realUrl = extractLegacySizedSource(url) ?? getLatestUrl(url);
|
|
651
685
|
const pHash = extractPHash(realUrl);
|
|
652
686
|
const options = {
|
|
653
687
|
format,
|
|
@@ -707,6 +741,7 @@ function isPictureEligibleRawUrl(rawUrl) {
|
|
|
707
741
|
return false;
|
|
708
742
|
}
|
|
709
743
|
if (u.protocol !== "http:" && u.protocol !== "https:") return false;
|
|
744
|
+
if (isLegacySizedProxyUrl(rawUrl)) return true;
|
|
710
745
|
const host = `${u.protocol}//${u.host}`;
|
|
711
746
|
const isProxyHost = host === proxyBase || host === "https://images.ecency.com";
|
|
712
747
|
if (isProxyHost && (u.pathname.startsWith("/p/") || u.pathname.startsWith("/u/") || SIZED_PROXY_PATH.test(u.pathname))) {
|
|
@@ -1756,6 +1791,9 @@ function linkify(content, forApp, renderOptions) {
|
|
|
1756
1791
|
const tag2 = tag.trim().substring(1);
|
|
1757
1792
|
const tagLower = tag2.toLowerCase();
|
|
1758
1793
|
if (!forApp) {
|
|
1794
|
+
if (renderOptions?.inertAuthorAndTagChips) {
|
|
1795
|
+
return `${preceding}<span class="er-tag er-tag-link">${tag.trim()}</span>`;
|
|
1796
|
+
}
|
|
1759
1797
|
return `${preceding}<a class="er-tag er-tag-link" href="/trending/${tagLower}">${tag.trim()}</a>`;
|
|
1760
1798
|
}
|
|
1761
1799
|
return `${preceding}<a class="markdown-tag-link" data-tag="${tagLower}">${tag.trim()}</a>`;
|
|
@@ -1769,7 +1807,8 @@ function linkify(content, forApp, renderOptions) {
|
|
|
1769
1807
|
if (userLower.indexOf("/") === -1 && isValidUsername(user)) {
|
|
1770
1808
|
if (!forApp) {
|
|
1771
1809
|
const avatarSrc = `${getProxyBase()}/u/${userLower}/avatar/small`;
|
|
1772
|
-
const
|
|
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>`;
|
|
1773
1812
|
const placeholder = `\u200C${authorPlaceholders.length}\u200C`;
|
|
1774
1813
|
authorPlaceholders.push({ placeholder, html });
|
|
1775
1814
|
return placeholder;
|
|
@@ -1834,6 +1873,19 @@ function hasAncestor(node, tagNames) {
|
|
|
1834
1873
|
}
|
|
1835
1874
|
return false;
|
|
1836
1875
|
}
|
|
1876
|
+
var CHIP_CLASSES = ["er-author-link", "er-tag-link"];
|
|
1877
|
+
function hasChipAncestor(node) {
|
|
1878
|
+
let current = node.parentNode;
|
|
1879
|
+
while (current) {
|
|
1880
|
+
const el = current;
|
|
1881
|
+
const className = typeof el.getAttribute === "function" ? el.getAttribute("class") : null;
|
|
1882
|
+
if (className && className.split(/\s+/).some((token) => CHIP_CLASSES.includes(token))) {
|
|
1883
|
+
return true;
|
|
1884
|
+
}
|
|
1885
|
+
current = current.parentNode;
|
|
1886
|
+
}
|
|
1887
|
+
return false;
|
|
1888
|
+
}
|
|
1837
1889
|
function text(node, forApp, renderOptions) {
|
|
1838
1890
|
if (!node || !node.parentNode) {
|
|
1839
1891
|
return;
|
|
@@ -1841,8 +1893,11 @@ function text(node, forApp, renderOptions) {
|
|
|
1841
1893
|
if (hasAncestor(node, ["a", "code", "pre"])) {
|
|
1842
1894
|
return;
|
|
1843
1895
|
}
|
|
1896
|
+
if (renderOptions?.inertAuthorAndTagChips && hasChipAncestor(node)) {
|
|
1897
|
+
return;
|
|
1898
|
+
}
|
|
1844
1899
|
const nodeValue = node.nodeValue || "";
|
|
1845
|
-
const linkified = linkify(nodeValue, forApp);
|
|
1900
|
+
const linkified = linkify(nodeValue, forApp, renderOptions);
|
|
1846
1901
|
if (linkified !== nodeValue) {
|
|
1847
1902
|
const doc = DOMParser.parseFromString(
|
|
1848
1903
|
`<span class="wr">${linkified}</span>`,
|
|
@@ -1930,7 +1985,7 @@ function traverse(node, forApp, depth = 0, state = { firstImageFound: false }, p
|
|
|
1930
1985
|
iframe(child, parentDomain, forApp, renderOptions);
|
|
1931
1986
|
}
|
|
1932
1987
|
if (child.nodeName === "#text") {
|
|
1933
|
-
text(child, forApp);
|
|
1988
|
+
text(child, forApp, renderOptions);
|
|
1934
1989
|
}
|
|
1935
1990
|
if (child.nodeName.toLowerCase() === "img") {
|
|
1936
1991
|
img(child, state, forApp);
|
|
@@ -2134,7 +2189,7 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
|
|
|
2134
2189
|
logIfSlow(performance.now() - t02, `body_len=${obj.length}`);
|
|
2135
2190
|
return res2;
|
|
2136
2191
|
}
|
|
2137
|
-
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}`;
|
|
2192
|
+
const key = `${makeEntryCacheKey(obj)}-md-${forApp ? "app" : "site"}-${parentDomain}${seoContext ? `-seo${seoContext.authorReputation ?? ""}-${seoContext.postPayout ?? ""}` : ""}${renderOptions?.embedVideosDirectly ? "-embed" : ""}${renderOptions?.inertAuthorAndTagChips ? "-inert" : ""}`;
|
|
2138
2193
|
const item = cacheGet(key);
|
|
2139
2194
|
if (item) {
|
|
2140
2195
|
return item;
|
|
@@ -2414,6 +2469,7 @@ exports.buildSrcSetForFormat = buildSrcSetForFormat;
|
|
|
2414
2469
|
exports.catchPostImage = catchPostImage;
|
|
2415
2470
|
exports.getEntryImageRawUrl = getEntryImageRawUrl;
|
|
2416
2471
|
exports.isAllowedEmbedSrc = isAllowedEmbedSrc;
|
|
2472
|
+
exports.isLegacySizedProxyUrl = isLegacySizedProxyUrl;
|
|
2417
2473
|
exports.isPictureEligibleRawUrl = isPictureEligibleRawUrl;
|
|
2418
2474
|
exports.isValidPermlink = isValidPermlink;
|
|
2419
2475
|
exports.postBodySummary = getPostBodySummary;
|