@ecency/render-helper 2.2.21 → 2.2.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecency/render-helper",
3
- "version": "2.2.21",
3
+ "version": "2.2.23",
4
4
  "description": "Markdown+Html Render helper",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -4,6 +4,12 @@ import { createDoc, makeEntryCacheKey } from './helper'
4
4
  import { cacheGet, cacheSet } from './cache'
5
5
  import { Entry } from './types'
6
6
 
7
+ const gifLinkRegex = /\.(gif)$/i;
8
+
9
+ function isGifLink(link: string) {
10
+ return gifLinkRegex.test(link);
11
+ }
12
+
7
13
  function getImage(entry: Entry, width = 0, height = 0, format = 'match'): string | null {
8
14
  /*
9
15
  * Return from json metadata if exists
@@ -21,6 +27,9 @@ function getImage(entry: Entry, width = 0, height = 0, format = 'match'): string
21
27
  }
22
28
 
23
29
  if (meta && meta.image && !!meta.image.length && meta.image[0]) {
30
+ if (isGifLink(meta.image[0])) {
31
+ return proxifyImageSrc(meta.image[0], 0, 0, format)
32
+ }
24
33
  return proxifyImageSrc(meta.image[0], width, height, format)
25
34
  }
26
35
 
@@ -34,6 +43,9 @@ function getImage(entry: Entry, width = 0, height = 0, format = 'match'): string
34
43
  const imgEls = doc.getElementsByTagName('img')
35
44
  if (imgEls.length >= 1) {
36
45
  const src = imgEls[0].getAttribute('src')
46
+ if (isGifLink(src)) {
47
+ return proxifyImageSrc(src, 0, 0, format)
48
+ }
37
49
  return proxifyImageSrc(src, width, height, format)
38
50
  }
39
51
 
@@ -20,9 +20,9 @@ export function linkify(content: string, forApp: boolean, webp: boolean): string
20
20
  (match, preceeding1, preceeding2, user) => {
21
21
  const userLower = user.toLowerCase()
22
22
  const preceedings = (preceeding1 || '') + (preceeding2 || '')
23
- if (userLower.indexOf('/')===-1) {
23
+ if (userLower.indexOf('/') === -1) {
24
24
  const attrs = forApp ? `data-author="${userLower}"` : `href="/@${userLower}"`
25
- return `${preceedings}<a class="markdown-author-link" ${attrs}>@${user}</a>`
25
+ return `${preceedings}<a class="markdown-author-link" ${attrs}>@${user}</a>`
26
26
  } else {
27
27
  return match
28
28
  }
@@ -32,14 +32,14 @@ export function linkify(content: string, forApp: boolean, webp: boolean): string
32
32
  // internal links
33
33
  content = content.replace(
34
34
  /((^|\s)(\/|)@[\w.\d-]+)\/(\S+)/gi, (match, u, p1, p2, p3) => {
35
- const uu = u.trim().toLowerCase().replace('/@','').replace('@','');
35
+ const uu = u.trim().toLowerCase().replace('/@', '').replace('@', '');
36
36
  const perm = p3;
37
37
  if (SECTION_LIST.some(v => p3.includes(v))) {
38
38
  const attrs = forApp ? `https://ecency.com/@${uu}/${perm}` : `href="/@${uu}/${perm}"`
39
39
  return ` <a class="markdown-profile-link" ${attrs}>@${uu}/${perm}</a>`
40
40
  } else {
41
41
  const attrs = forApp ? `data-author="${uu}" data-tag="post" data-permlink="${perm}"` : `href="/post/@${uu}/${perm}"`
42
- return ` <a class="markdown-post-link" ${attrs}>@${uu}/${perm}</a>`
42
+ return ` <a class="markdown-post-link" ${attrs}>@${uu}/${perm}</a>`
43
43
  }
44
44
  }
45
45
  )
@@ -9,6 +9,11 @@ const { linkify } = require('remarkable/linkify')
9
9
 
10
10
 
11
11
  export function markdownToHTML(input: string, forApp: boolean, webp: boolean): string {
12
+ // Internalize leofinance.io links
13
+ input = input.replace("https://leofinance.io/threads/view/", "/@");
14
+ input = input.replace("https://leofinance.io/posts/", "/@");
15
+
16
+
12
17
  const md = new Remarkable({
13
18
  html: true,
14
19
  breaks: true,