@ecency/render-helper 2.5.38 → 2.5.39
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.js +83 -20
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +83 -20
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.mjs +83 -20
- package/dist/node/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -90,7 +90,7 @@ var INTERNAL_POST_TAG_REGEX = /^(.+?)\/(@[\w.\d-]+)\/(.*)$/i;
|
|
|
90
90
|
var INTERNAL_POST_REGEX = /^\/(@[\w.\d-]+)\/(.*)$/i;
|
|
91
91
|
var CUSTOM_COMMUNITY_REGEX = /^https?:\/\/(.*)\/c\/(hive-\d+)(.*)/i;
|
|
92
92
|
var YOUTUBE_REGEX = /(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|shorts\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/i;
|
|
93
|
-
var YOUTUBE_EMBED_REGEX = /^(https?:)?\/\/www\.youtube\.com\/(embed|shorts)\/.*/i;
|
|
93
|
+
var YOUTUBE_EMBED_REGEX = /^(https?:)?\/\/(?:www\.|m\.)?youtube\.com\/(embed|shorts)\/.*/i;
|
|
94
94
|
var VIMEO_REGEX = /(https?:\/\/)?(www\.)?(?:vimeo)\.com.*(?:videos|video|channels|)\/([\d]+)/i;
|
|
95
95
|
var VIMEO_EMBED_REGEX = /https:\/\/player\.vimeo\.com\/video\/([0-9]+)(?:$|[?#])/;
|
|
96
96
|
var BITCHUTE_REGEX = /^(?:https?:\/\/)?(?:www\.)?bitchute\.com\/(?:video|embed)\/([a-z0-9]+)/i;
|
|
@@ -444,8 +444,31 @@ function createDoc(html) {
|
|
|
444
444
|
return null;
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
|
+
function hashBody(body) {
|
|
448
|
+
const s = typeof body === "string" ? body : "";
|
|
449
|
+
let h = 2166136261;
|
|
450
|
+
for (let i2 = 0; i2 < s.length; i2++) {
|
|
451
|
+
h ^= s.charCodeAt(i2);
|
|
452
|
+
h = Math.imul(h, 16777619);
|
|
453
|
+
}
|
|
454
|
+
return `${s.length}.${(h >>> 0).toString(36)}`;
|
|
455
|
+
}
|
|
456
|
+
var bodyHashes = /* @__PURE__ */ new WeakMap();
|
|
457
|
+
function entryBodyHash(entry) {
|
|
458
|
+
const body = entry.body;
|
|
459
|
+
if (typeof body !== "string" || typeof entry !== "object" || entry === null) {
|
|
460
|
+
return hashBody(body);
|
|
461
|
+
}
|
|
462
|
+
const stored = bodyHashes.get(entry);
|
|
463
|
+
if (stored && stored.body === body) {
|
|
464
|
+
return stored.hash;
|
|
465
|
+
}
|
|
466
|
+
const hash = hashBody(body);
|
|
467
|
+
bodyHashes.set(entry, { body, hash });
|
|
468
|
+
return hash;
|
|
469
|
+
}
|
|
447
470
|
function makeEntryCacheKey(entry) {
|
|
448
|
-
return `${entry.author}-${entry.permlink}-${entry.last_update}-${entry.updated}`;
|
|
471
|
+
return `${entry.author}-${entry.permlink}-${entry.last_update}-${entry.updated}-${entryBodyHash(entry)}`;
|
|
449
472
|
}
|
|
450
473
|
function stripHtmlTags(s) {
|
|
451
474
|
const n = s.length;
|
|
@@ -537,6 +560,10 @@ function extractYtStartTime(url) {
|
|
|
537
560
|
return "";
|
|
538
561
|
}
|
|
539
562
|
}
|
|
563
|
+
function youtubeVideoLinkClass(matchedUrl) {
|
|
564
|
+
const base = "markdown-video-link markdown-video-link-youtube";
|
|
565
|
+
return /youtube\.com\/shorts\//i.test(matchedUrl) ? `${base} markdown-video-link-youtube-portrait` : base;
|
|
566
|
+
}
|
|
540
567
|
function sanitizePermlink(permlink) {
|
|
541
568
|
if (!permlink || typeof permlink !== "string") {
|
|
542
569
|
return "";
|
|
@@ -1338,7 +1365,8 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
|
1338
1365
|
}
|
|
1339
1366
|
let match = href.match(YOUTUBE_REGEX);
|
|
1340
1367
|
if (match && match[1] && el.textContent.trim() === href) {
|
|
1341
|
-
|
|
1368
|
+
const videoClass = youtubeVideoLinkClass(match[0]);
|
|
1369
|
+
el.setAttribute("class", videoClass);
|
|
1342
1370
|
el.removeAttribute("href");
|
|
1343
1371
|
const vid = match[1];
|
|
1344
1372
|
const thumbnail = proxifyImageSrc(`https://img.youtube.com/vi/${vid.split("?")[0]}/hqdefault.jpg`, 0, 0, "match");
|
|
@@ -1363,7 +1391,7 @@ function a(el, forApp, parentDomain = "ecency.com", seoContext, renderOptions) {
|
|
|
1363
1391
|
iframe2.setAttribute("allowfullscreen", "");
|
|
1364
1392
|
wrapper.appendChild(iframe2);
|
|
1365
1393
|
el.appendChild(wrapper);
|
|
1366
|
-
el.setAttribute("class",
|
|
1394
|
+
el.setAttribute("class", `${videoClass} er-youtube`);
|
|
1367
1395
|
} else {
|
|
1368
1396
|
const thumbImg = el.ownerDocument.createElement("img");
|
|
1369
1397
|
thumbImg.setAttribute("class", "no-replace video-thumbnail");
|
|
@@ -1635,8 +1663,20 @@ function iframe(el, parentDomain = "ecency.com", forApp = false, renderOptions)
|
|
|
1635
1663
|
el.parentNode.removeChild(el);
|
|
1636
1664
|
return;
|
|
1637
1665
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1666
|
+
const ytMatch = src.match(YOUTUBE_EMBED_REGEX);
|
|
1667
|
+
if (ytMatch) {
|
|
1668
|
+
let stripped = stripQueryString(src);
|
|
1669
|
+
if (!/^(https?:)?\/\/www\./i.test(stripped)) {
|
|
1670
|
+
stripped = stripped.replace(/^(https?:)?\/\/(?:m\.)?youtube\.com/i, "https://www.youtube.com");
|
|
1671
|
+
}
|
|
1672
|
+
el.setAttribute("src", stripped);
|
|
1673
|
+
if (ytMatch[2].toLowerCase() === "shorts") {
|
|
1674
|
+
const shortId = stripped.match(/\/shorts\/([A-Za-z0-9_-]{11})\/?(?=[?#]|$)/i);
|
|
1675
|
+
if (shortId) {
|
|
1676
|
+
el.setAttribute("src", `https://www.youtube.com/embed/${shortId[1]}`);
|
|
1677
|
+
el.setAttribute("class", "portrait-embed");
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1640
1680
|
return;
|
|
1641
1681
|
}
|
|
1642
1682
|
if (src.match(BITCHUTE_REGEX)) {
|
|
@@ -1960,7 +2000,7 @@ function text(node, forApp, renderOptions) {
|
|
|
1960
2000
|
const startTime = extractYtStartTime(nodeValue);
|
|
1961
2001
|
const container = node.ownerDocument.createElement("p");
|
|
1962
2002
|
const anchor = node.ownerDocument.createElement("a");
|
|
1963
|
-
anchor.setAttribute("class",
|
|
2003
|
+
anchor.setAttribute("class", youtubeVideoLinkClass(e[0]));
|
|
1964
2004
|
anchor.setAttribute("data-embed-src", embedSrc);
|
|
1965
2005
|
anchor.setAttribute("data-youtube", vid);
|
|
1966
2006
|
if (startTime) {
|
|
@@ -10243,11 +10283,16 @@ var cache = new lruCache.LRUCache({ max: 500 });
|
|
|
10243
10283
|
function setCacheSize(size) {
|
|
10244
10284
|
cache = new lruCache.LRUCache({ max: size });
|
|
10245
10285
|
}
|
|
10246
|
-
|
|
10247
|
-
|
|
10286
|
+
var MEMO_MISS = /* @__PURE__ */ Symbol("memo-miss");
|
|
10287
|
+
function entryMemoGet(key, body, meta) {
|
|
10288
|
+
const slot = cache.get(key);
|
|
10289
|
+
if (slot === void 0 || slot.body !== body || slot.meta !== meta) {
|
|
10290
|
+
return MEMO_MISS;
|
|
10291
|
+
}
|
|
10292
|
+
return slot.value;
|
|
10248
10293
|
}
|
|
10249
|
-
function
|
|
10250
|
-
cache.set(key, value);
|
|
10294
|
+
function entryMemoSet(key, body, meta, value) {
|
|
10295
|
+
cache.set(key, { body, meta, value });
|
|
10251
10296
|
}
|
|
10252
10297
|
|
|
10253
10298
|
// src/markdown-2-html.ts
|
|
@@ -10272,8 +10317,8 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
|
|
|
10272
10317
|
return res2;
|
|
10273
10318
|
}
|
|
10274
10319
|
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 : ""}`;
|
|
10275
|
-
const item =
|
|
10276
|
-
if (item) {
|
|
10320
|
+
const item = entryMemoGet(key, obj.body);
|
|
10321
|
+
if (item !== MEMO_MISS) {
|
|
10277
10322
|
return item;
|
|
10278
10323
|
}
|
|
10279
10324
|
const cleanBody = cleanReply(obj.body);
|
|
@@ -10283,7 +10328,7 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
|
|
|
10283
10328
|
performance.now() - t0,
|
|
10284
10329
|
`author=@${obj.author} permlink=${obj.permlink} body_len=${obj.body?.length ?? 0}`
|
|
10285
10330
|
);
|
|
10286
|
-
|
|
10331
|
+
entryMemoSet(key, obj.body, void 0, res);
|
|
10287
10332
|
return res;
|
|
10288
10333
|
}
|
|
10289
10334
|
|
|
@@ -10791,6 +10836,23 @@ function firstMetaUrl(value) {
|
|
|
10791
10836
|
}
|
|
10792
10837
|
return void 0;
|
|
10793
10838
|
}
|
|
10839
|
+
function metaFingerprint(jsonMetadata) {
|
|
10840
|
+
let meta;
|
|
10841
|
+
if (typeof jsonMetadata === "object") {
|
|
10842
|
+
meta = jsonMetadata;
|
|
10843
|
+
} else {
|
|
10844
|
+
try {
|
|
10845
|
+
meta = JSON.parse(jsonMetadata);
|
|
10846
|
+
} catch {
|
|
10847
|
+
meta = null;
|
|
10848
|
+
}
|
|
10849
|
+
}
|
|
10850
|
+
try {
|
|
10851
|
+
return JSON.stringify([meta?.thumbnails, meta?.image]);
|
|
10852
|
+
} catch {
|
|
10853
|
+
return {};
|
|
10854
|
+
}
|
|
10855
|
+
}
|
|
10794
10856
|
function proxifyFound(src, width, height, format) {
|
|
10795
10857
|
return proxifyImageSrc(decodeEntities(src), width, height, format);
|
|
10796
10858
|
}
|
|
@@ -10913,12 +10975,13 @@ function catchPostImage(obj, width = 0, height = 0, format = "match", options =
|
|
|
10913
10975
|
return null;
|
|
10914
10976
|
}
|
|
10915
10977
|
const key = `${makeEntryCacheKey(obj)}-${width}x${height}-${format}${fastMode ? "-fast" : ""}`;
|
|
10916
|
-
const
|
|
10917
|
-
|
|
10978
|
+
const meta = metaFingerprint(obj.json_metadata);
|
|
10979
|
+
const item = entryMemoGet(key, obj.body, meta);
|
|
10980
|
+
if (item !== MEMO_MISS) {
|
|
10918
10981
|
return item;
|
|
10919
10982
|
}
|
|
10920
10983
|
const res = getImage(obj, width, height, format, fastMode);
|
|
10921
|
-
|
|
10984
|
+
entryMemoSet(key, obj.body, meta, res);
|
|
10922
10985
|
return res;
|
|
10923
10986
|
}
|
|
10924
10987
|
|
|
@@ -11005,12 +11068,12 @@ function getPostBodySummary(obj, length, platform) {
|
|
|
11005
11068
|
return postBodySummary(obj, normalizedLength, normalizedPlatform);
|
|
11006
11069
|
}
|
|
11007
11070
|
const key = `${makeEntryCacheKey(obj)}-sum-${normalizedLength}-${normalizedPlatform}`;
|
|
11008
|
-
const item =
|
|
11009
|
-
if (item) {
|
|
11071
|
+
const item = entryMemoGet(key, obj.body);
|
|
11072
|
+
if (item !== MEMO_MISS) {
|
|
11010
11073
|
return item;
|
|
11011
11074
|
}
|
|
11012
11075
|
const res = postBodySummary(obj.body, normalizedLength, normalizedPlatform);
|
|
11013
|
-
|
|
11076
|
+
entryMemoSet(key, obj.body, void 0, res);
|
|
11014
11077
|
return res;
|
|
11015
11078
|
}
|
|
11016
11079
|
|