@ecency/render-helper 2.5.34 → 2.5.36

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.
@@ -75,6 +75,17 @@ declare function markdown2Html(obj: Entry | string, forApp?: boolean, _webp?: bo
75
75
  * URL). Returns null when the fast path finds no unambiguous image (the caller
76
76
  * can fall back to catchPostImage).
77
77
  */
78
+ /**
79
+ * The RAW (pre-proxify) URL of the image a CARD renders.
80
+ *
81
+ * Mirrors catchPostImage's precedence — `json_metadata.thumbnails` first, then
82
+ * `json_metadata.image`, then the first body image — which is NOT the order
83
+ * getEntryImageRawUrl uses: that one answers a body/LCP-preload question and
84
+ * deliberately skips thumbnails. Use this when a caller has to reason about the
85
+ * file the card will actually request (its extension, say), or it can end up
86
+ * inspecting one asset while the card renders another.
87
+ */
88
+ declare function getEntryCardImageRawUrl(obj: Entry | string): string | null;
78
89
  declare function getEntryImageRawUrl(obj: Entry | string): string | null;
79
90
  interface CatchPostImageOptions {
80
91
  /**
@@ -200,4 +211,4 @@ declare function isValidPermlink(permlink: string): boolean;
200
211
  */
201
212
  declare function simpleMarkdownToHTML(input: string): string;
202
213
 
203
- export { type Entry, IMAGE_SIZES, type ProxifyOptions, type RenderOptions, SECTION_LIST, type SeoContext, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryImageRawUrl, isAllowedEmbedSrc, isLegacySizedProxyUrl, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
214
+ export { type Entry, IMAGE_SIZES, type ProxifyOptions, type RenderOptions, SECTION_LIST, type SeoContext, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryCardImageRawUrl, getEntryImageRawUrl, isAllowedEmbedSrc, isLegacySizedProxyUrl, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
@@ -2210,10 +2210,6 @@ function markdown2Html(obj, forApp = true, _webp = false, parentDomain = "ecency
2210
2210
  }
2211
2211
 
2212
2212
  // src/catch-post-image.ts
2213
- var gifLinkRegex = /\.(gif)$/i;
2214
- function isGifLink(link) {
2215
- return gifLinkRegex.test(link);
2216
- }
2217
2213
  var BACKTICK_FENCE_RE = /```[\s\S]*?```/g;
2218
2214
  var TILDE_FENCE_RE = /~~~[\s\S]*?~~~/g;
2219
2215
  var INLINE_CODE_RE = /`[^`\n]*`/g;
@@ -2718,11 +2714,7 @@ function firstMetaUrl(value) {
2718
2714
  return void 0;
2719
2715
  }
2720
2716
  function proxifyFound(src, width, height, format) {
2721
- const decoded = decodeEntities(src);
2722
- if (isGifLink(decoded)) {
2723
- return proxifyImageSrc(decoded, 0, 0, format);
2724
- }
2725
- return proxifyImageSrc(decoded, width, height, format);
2717
+ return proxifyImageSrc(decodeEntities(src), width, height, format);
2726
2718
  }
2727
2719
  function getImage(entry, width = 0, height = 0, format = "match", fastMode = false) {
2728
2720
  let meta;
@@ -2737,29 +2729,17 @@ function getImage(entry, width = 0, height = 0, format = "match", fastMode = fal
2737
2729
  }
2738
2730
  const thumbnail = firstMetaUrl(meta?.thumbnails);
2739
2731
  if (thumbnail) {
2740
- const decodedThumbnail = decodeEntities(thumbnail);
2741
- const proxied = isGifLink(decodedThumbnail) ? proxifyImageSrc(decodedThumbnail, 0, 0, format) : proxifyImageSrc(decodedThumbnail, width, height, format);
2732
+ const proxied = proxifyImageSrc(decodeEntities(thumbnail), width, height, format);
2742
2733
  if (proxied) {
2743
2734
  return proxied;
2744
2735
  }
2745
2736
  }
2746
2737
  if (meta && typeof meta.image === "string" && meta.image.length > 0) {
2747
- const decodedImage = decodeEntities(meta.image);
2748
- if (isGifLink(decodedImage)) {
2749
- return proxifyImageSrc(decodedImage, 0, 0, format);
2750
- }
2751
- return proxifyImageSrc(decodedImage, width, height, format);
2738
+ return proxifyImageSrc(decodeEntities(meta.image), width, height, format);
2752
2739
  }
2753
2740
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
2754
2741
  if (typeof meta.image[0] === "string") {
2755
- const decodedImage = decodeEntities(meta.image[0]);
2756
- if (isGifLink(decodedImage)) {
2757
- return proxifyImageSrc(decodedImage, 0, 0, format);
2758
- }
2759
- return proxifyImageSrc(decodedImage, width, height, format);
2760
- }
2761
- if (isGifLink(meta.image[0])) {
2762
- return proxifyImageSrc(meta.image[0], 0, 0, format);
2742
+ return proxifyImageSrc(decodeEntities(meta.image[0]), width, height, format);
2763
2743
  }
2764
2744
  return proxifyImageSrc(meta.image[0], width, height, format);
2765
2745
  }
@@ -2785,6 +2765,26 @@ function getImage(entry, width = 0, height = 0, format = "match", fastMode = fal
2785
2765
  }
2786
2766
  return null;
2787
2767
  }
2768
+ function getEntryCardImageRawUrl(obj) {
2769
+ if (typeof obj === "string") {
2770
+ return getEntryImageRawUrl(obj);
2771
+ }
2772
+ let meta;
2773
+ if (typeof obj.json_metadata === "object") {
2774
+ meta = obj.json_metadata;
2775
+ } else {
2776
+ try {
2777
+ meta = JSON.parse(obj.json_metadata);
2778
+ } catch (e) {
2779
+ meta = null;
2780
+ }
2781
+ }
2782
+ const thumbnail = firstMetaUrl(meta?.thumbnails);
2783
+ if (thumbnail) {
2784
+ return decodeImageSrc(thumbnail);
2785
+ }
2786
+ return getEntryImageRawUrl(obj);
2787
+ }
2788
2788
  function getEntryImageRawUrl(obj) {
2789
2789
  if (typeof obj === "string") {
2790
2790
  const src = findFirstImageUrl(obj, true);
@@ -2934,6 +2934,6 @@ function getPostBodySummary(obj, length, platform) {
2934
2934
  return res;
2935
2935
  }
2936
2936
 
2937
- 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 };
2937
+ export { IMAGE_SIZES, SECTION_LIST, buildPictureSources, buildSrcSet, buildSrcSetForFormat, catchPostImage, getEntryCardImageRawUrl, getEntryImageRawUrl, isAllowedEmbedSrc, isLegacySizedProxyUrl, isPictureEligibleRawUrl, isValidPermlink, getPostBodySummary as postBodySummary, proxifyImageSrc, markdown2Html as renderPostBody, setCacheSize, setProxyBase, setSlowRenderThresholdMs, simpleMarkdownToHTML };
2938
2938
  //# sourceMappingURL=index.js.map
2939
2939
  //# sourceMappingURL=index.js.map