@ecency/render-helper 2.5.42 → 2.5.44
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/README.md +2 -2
- package/dist/browser/index.js +36 -15
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +36 -15
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +36 -15
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,7 +35,7 @@ Built and maintained by [Ecency](https://ecency.com), an open-source social plat
|
|
|
35
35
|
- `postBodySummary` - Generate text summary from post body
|
|
36
36
|
- `proxifyImageSrc` - Proxify image URLs through Ecency's image server
|
|
37
37
|
- `setProxyBase` - Configure image proxy endpoint (default: `https://i.ecency.com`)
|
|
38
|
-
- `setCacheSize` - Configure LRU cache size (default:
|
|
38
|
+
- `setCacheSize` - Configure LRU cache size (default: 500 entries)
|
|
39
39
|
|
|
40
40
|
### Processing Pipeline
|
|
41
41
|
|
|
@@ -95,7 +95,7 @@ Built and maintained by [Ecency](https://ecency.com), an open-source social plat
|
|
|
95
95
|
- LRU cache v11 (`src/cache.ts`) stores rendered HTML and extracted images
|
|
96
96
|
- Cache keys include content hash (last_update, updated) to auto-invalidate
|
|
97
97
|
- Separate cache entries for different image sizes and formats
|
|
98
|
-
- Default size:
|
|
98
|
+
- Default size: 500 entries
|
|
99
99
|
- Uses modern `LRUCache` named import from lru-cache v11
|
|
100
100
|
|
|
101
101
|
## File Structure
|
package/dist/browser/index.js
CHANGED
|
@@ -524,13 +524,13 @@ function extractYtStartTime(url) {
|
|
|
524
524
|
try {
|
|
525
525
|
const urlObj = new URL(url);
|
|
526
526
|
const params = new URLSearchParams(urlObj.search);
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
return params.get("start") || "";
|
|
527
|
+
const m = /^(?:(\d{1,7})h)?(?:(\d{1,7})m)?(?:(\d{1,7})s?)?$/i.exec(params.get("t") || "");
|
|
528
|
+
if (m && (m[1] || m[2] || m[3])) {
|
|
529
|
+
const seconds = +(m[1] || 0) * 3600 + +(m[2] || 0) * 60 + +(m[3] || 0);
|
|
530
|
+
if (seconds <= 9999999) return "" + seconds;
|
|
532
531
|
}
|
|
533
|
-
|
|
532
|
+
const start = params.get("start") || "";
|
|
533
|
+
return /^\d{1,7}$/.test(start) ? "" + +start : "";
|
|
534
534
|
} catch (error) {
|
|
535
535
|
return "";
|
|
536
536
|
}
|
|
@@ -873,6 +873,15 @@ function sanitizeHtml(html, options) {
|
|
|
873
873
|
return preserveImageDimensions ? enforceImageDimensionPair(withoutBareSource) : withoutBareSource;
|
|
874
874
|
}
|
|
875
875
|
|
|
876
|
+
// src/methods/internal-thumbnail.ts
|
|
877
|
+
var internalThumbnails = /* @__PURE__ */ new WeakSet();
|
|
878
|
+
function markInternalThumbnail(el) {
|
|
879
|
+
internalThumbnails.add(el);
|
|
880
|
+
}
|
|
881
|
+
function isInternalThumbnail(el) {
|
|
882
|
+
return internalThumbnails.has(el);
|
|
883
|
+
}
|
|
884
|
+
|
|
876
885
|
// src/methods/img.method.ts
|
|
877
886
|
var IMAGE_SIZES = "(max-width: 768px) 100vw, 700px";
|
|
878
887
|
function wrapInPicture(el, rawUrl) {
|
|
@@ -947,32 +956,40 @@ function img(el, state, forApp = true, renderOptions) {
|
|
|
947
956
|
if (isAvatar || imageIndex !== 0) {
|
|
948
957
|
el.removeAttribute("fetchpriority");
|
|
949
958
|
}
|
|
950
|
-
const
|
|
951
|
-
const shouldReplace = !cls.includes("no-replace");
|
|
959
|
+
const shouldReplace = !isInternalThumbnail(el);
|
|
952
960
|
const base = trimTrailingSlash(getProxyBase());
|
|
953
961
|
const hasAlreadyProxied = src.startsWith(`${base}/p/`) || src.startsWith(`${base}/u/`) || new RegExp(`^${base.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/\\d+x\\d+/`).test(src);
|
|
954
962
|
if (shouldReplace && !hasAlreadyProxied) {
|
|
955
963
|
const proxified = proxifyImageSrc(decodedSrc, 0, 0, "match", { forceProxy: true });
|
|
956
964
|
if (proxified) {
|
|
957
965
|
el.setAttribute("src", proxified);
|
|
958
|
-
const
|
|
959
|
-
if (
|
|
960
|
-
el.setAttribute("srcset",
|
|
966
|
+
const srcset2 = buildSrcSet(decodedSrc);
|
|
967
|
+
if (srcset2) {
|
|
968
|
+
el.setAttribute("srcset", srcset2);
|
|
961
969
|
el.setAttribute("sizes", IMAGE_SIZES);
|
|
962
970
|
}
|
|
963
971
|
if (!forApp) {
|
|
964
972
|
wrapInPicture(el, decodedSrc);
|
|
965
973
|
}
|
|
974
|
+
} else if (/^https?:\/\//i.test(decodedSrc)) {
|
|
975
|
+
el.removeAttribute("src");
|
|
976
|
+
el.removeAttribute("srcset");
|
|
977
|
+
el.removeAttribute("sizes");
|
|
966
978
|
}
|
|
967
979
|
} else if (shouldReplace && hasAlreadyProxied) {
|
|
968
980
|
if (src.startsWith(`${base}/p/`)) {
|
|
969
|
-
const
|
|
970
|
-
if (
|
|
971
|
-
el.setAttribute("srcset",
|
|
981
|
+
const srcset2 = buildSrcSet(src);
|
|
982
|
+
if (srcset2) {
|
|
983
|
+
el.setAttribute("srcset", srcset2);
|
|
972
984
|
el.setAttribute("sizes", IMAGE_SIZES);
|
|
973
985
|
}
|
|
974
986
|
}
|
|
975
987
|
}
|
|
988
|
+
const srcset = shouldReplace ? el.getAttribute("srcset") : null;
|
|
989
|
+
if (srcset && srcset.split(",").some((c) => !c.trim().startsWith(`${base}/`))) {
|
|
990
|
+
el.removeAttribute("srcset");
|
|
991
|
+
el.removeAttribute("sizes");
|
|
992
|
+
}
|
|
976
993
|
}
|
|
977
994
|
function createImageHTML(src, isLCP, forApp = true) {
|
|
978
995
|
const decoded = decodeImageSrc(src);
|
|
@@ -1425,6 +1442,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
|
1425
1442
|
} else {
|
|
1426
1443
|
const thumbImg = el.ownerDocument.createElement("img");
|
|
1427
1444
|
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
1445
|
+
markInternalThumbnail(thumbImg);
|
|
1428
1446
|
thumbImg.setAttribute("itemprop", "thumbnailUrl");
|
|
1429
1447
|
thumbImg.setAttribute("src", thumbnail);
|
|
1430
1448
|
const play = el.ownerDocument.createElement("span");
|
|
@@ -1514,6 +1532,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
|
1514
1532
|
const thumbnail = proxifyImageSrc(src.replace(/\s+/g, ""), 0, 0, "match");
|
|
1515
1533
|
const thumbImg = el.ownerDocument.createElement("img");
|
|
1516
1534
|
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
1535
|
+
markInternalThumbnail(thumbImg);
|
|
1517
1536
|
thumbImg.setAttribute("itemprop", "thumbnailUrl");
|
|
1518
1537
|
thumbImg.setAttribute("src", thumbnail);
|
|
1519
1538
|
el.appendChild(thumbImg);
|
|
@@ -1574,6 +1593,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
|
1574
1593
|
const thumbnail = proxifyImageSrc(src.replace(/\s+/g, ""), 0, 0, "match");
|
|
1575
1594
|
const thumbImg = el.ownerDocument.createElement("img");
|
|
1576
1595
|
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
1596
|
+
markInternalThumbnail(thumbImg);
|
|
1577
1597
|
thumbImg.setAttribute("itemprop", "thumbnailUrl");
|
|
1578
1598
|
thumbImg.setAttribute("src", thumbnail);
|
|
1579
1599
|
el.appendChild(thumbImg);
|
|
@@ -2038,6 +2058,7 @@ function text(node, forApp, renderOptions) {
|
|
|
2038
2058
|
}
|
|
2039
2059
|
const thumbImg = node.ownerDocument.createElement("img");
|
|
2040
2060
|
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
2061
|
+
markInternalThumbnail(thumbImg);
|
|
2041
2062
|
thumbImg.setAttribute("src", thumbnail);
|
|
2042
2063
|
anchor.appendChild(thumbImg);
|
|
2043
2064
|
const play = node.ownerDocument.createElement("span");
|
|
@@ -2115,7 +2136,7 @@ function cleanReply(s) {
|
|
|
2115
2136
|
return (pre ? pre.split("\n").filter((item) => item.toLowerCase().includes("posted using [partiko") === false).filter((item) => item.toLowerCase().includes("posted using [dapplr") === false).filter((item) => item.toLowerCase().includes("posted using [leofinance") === false).filter((item) => item.toLowerCase().includes("posted via [neoxian") === false).filter((item) => item.toLowerCase().includes("posted using [neoxian") === false).filter((item) => item.toLowerCase().includes("posted via [first context") === false).filter((item) => item.toLowerCase().includes("posted with [stemgeeks") === false).filter((item) => item.toLowerCase().includes("posted using [bilpcoin") === false).filter((item) => item.toLowerCase().includes("posted using [inleo") === false).filter((item) => item.toLowerCase().includes("posted using [sportstalksocial]") === false).filter((item) => item.toLowerCase().includes("<center><sub>[posted using aeneas.blog") === false).filter((item) => item.toLowerCase().includes("<center><sub>posted via [proofofbrain.io") === false).filter((item) => item.toLowerCase().includes("<center>posted on [hypnochain") === false).filter((item) => item.toLowerCase().includes("<center><sub>posted via [weedcash.network") === false).filter((item) => item.toLowerCase().includes("<center>posted on [naturalmedicine.io") === false).filter((item) => item.toLowerCase().includes("<center><sub>posted via [musicforlife.io") === false).filter((item) => item.toLowerCase().includes("if the truvvl embed is unsupported by your current frontend, click this link to view this story") === false).filter((item) => item.toLowerCase().includes("<center><em>posted from truvvl") === false).filter((item) => item.toLowerCase().includes('view this post <a href="https://travelfeed.io/') === false).filter((item) => item.toLowerCase().includes("read this post on travelfeed.io for the best experience") === false).filter((item) => item.toLowerCase().includes('posted via <a href="https://www.dporn.co/"') === false).filter((item) => item.toLowerCase().includes("\u25B6\uFE0F [watch on 3speak](https://3speak") === false).filter((item) => item.toLowerCase().includes("<sup><sub>posted via [inji.com]") === false).filter((item) => item.toLowerCase().includes("view this post on [liketu]") === false).filter((item) => {
|
|
2116
2137
|
const l = item.toLowerCase();
|
|
2117
2138
|
return !(l.includes("posted from liketu speak") && l.includes("auto-transcrib"));
|
|
2118
|
-
}).filter((item) => item.toLowerCase().includes("originally posted through [scrobble.life") === false).filter((item) => item.toLowerCase().includes("*posted via lumen") === false).filter((item) => item.toLowerCase().includes("<sub>posted via [hivesuite](") === false).filter((item) => !/^[ \t]*▶\uFE0F?[ \t]*\[watch on 3speak\.tv\]\(https:\/\/3speak\.tv\/watch[^)\s]*\)\s*$/i.test(item)).filter((item) => item.toLowerCase().includes('view this post <a href="https://travelfeed.com/') === false).filter((item) => {
|
|
2139
|
+
}).filter((item) => item.toLowerCase().includes("originally posted through [scrobble.life") === false).filter((item) => item.toLowerCase().includes("*posted via lumen") === false).filter((item) => item.toLowerCase().includes("<sub>posted via [hivesuite](") === false).filter((item) => !/^\s*<sub>\[via hivesuite\]\(https:\/\/hivesuite\.app\/[^)\s]*\)<\/sub>\s*$/i.test(item)).filter((item) => !/^[ \t]*▶\uFE0F?[ \t]*\[watch on 3speak\.tv\]\(https:\/\/3speak\.tv\/watch[^)\s]*\)\s*$/i.test(item)).filter((item) => item.toLowerCase().includes('view this post <a href="https://travelfeed.com/') === false).filter((item) => {
|
|
2119
2140
|
const l = item.toLowerCase();
|
|
2120
2141
|
return !(l.includes("_posted from liketu clips") && l.includes("short video, trimmed"));
|
|
2121
2142
|
}).filter((item) => item.toLowerCase().includes("[via Inbox]") === false).filter((item) => item.toLowerCase().includes("<sub>[via apps from](") === false).join("\n") : "").replace('Posted via <a href="https://d.buzz" data-link="promote-link">D.Buzz</a>', "").replace('<div class="pull-right"><a href="/@hive.engage"></a></div>', "").replace('<div><a href="https://engage.hivechain.app"></a></div>', "").replace(`<div class="text-center"><img src="https://cdn.steemitimages.com/DQmNp6YwAm2qwquALZw8PdcovDorwaBSFuxQ38TrYziGT6b/A-20.png"><a href="https://bit.ly/actifit-app"><img src="https://cdn.steemitimages.com/DQmQqfpSmcQtfrHAtzfBtVccXwUL9vKNgZJ2j93m8WNjizw/l5.png"></a><a href="https://bit.ly/actifit-ios"><img src="https://cdn.steemitimages.com/DQmbWy8KzKT1UvCvznUTaFPw6wBUcyLtBT5XL9wdbB7Hfmn/l6.png"></a></div>`, "");
|