aboutsummaryrefslogtreecommitdiff
path: root/src/mixins/postUtils.pug
diff options
context:
space:
mode:
Diffstat (limited to 'src/mixins/postUtils.pug')
-rw-r--r--src/mixins/postUtils.pug42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/mixins/postUtils.pug b/src/mixins/postUtils.pug
index 816adf7..84add09 100644
--- a/src/mixins/postUtils.pug
+++ b/src/mixins/postUtils.pug
@@ -10,14 +10,14 @@
10 } 10 }
11- 11-
12 function postThumbnail(p) { 12 function postThumbnail(p) {
13 if (p.thumbnail == "image" || p.thumbnail == "") { 13 if (p.over_18) {
14 return p.url; 14 return "/nsfw.svg";
15 } else if (p.over_18) {
16 return "/nsfw.svg";
17 } else if (p.thumbnail == "spoiler") { 15 } else if (p.thumbnail == "spoiler") {
18 return "/spoiler.svg"; 16 return "/spoiler.svg";
17 } else if (p.thumbnail == "image" || p.thumbnail == "") {
18 return p.url;
19 } else { 19 } else {
20 return p.thumbnail; 20 return p.thumbnail;
21 } 21 }
22 } 22 }
23- 23-
@@ -51,3 +51,33 @@
51 return null; 51 return null;
52 } 52 }
53 } 53 }
54-
55 function convertInlineImageLinks(html) {
56 // Find all anchors that href to https://preview.redd.it
57 const expression = /<a href="https:\/\/preview\.redd\.it.*?">(.*?)<\/a>/g;
58 const matches = html.matchAll(expression);
59 var result = html;
60 matches.forEach((match) => {
61 // Replace each occurrence with an actual img tag
62 result = result.replace(match[0], '<a href="' + match[1] + '"><img src="' + match[1] + '"></a>');
63 })
64
65 return result;
66 }
67-
68 function decodePostVideoUrls(p) {
69 // Video URLs have querystring separators that are HTML-encoded, so replace them.
70 const expression = /&amp;/g;
71
72 var hls_url = p.secure_media && p.secure_media.reddit_video && p.secure_media.reddit_video.hls_url ? p.secure_media.reddit_video.hls_url.replace(expression, '&') : '';
73
74 var dash_url = p.secure_media && p.secure_media.reddit_video && p.secure_media.reddit_video.dash_url ? p.secure_media.reddit_video.dash_url.replace(expression, '&') : '';
75
76 var fallback_url = p.secure_media && p.secure_media.reddit_video && p.secure_media.reddit_video.fallback_url ? p.secure_media.reddit_video.fallback_url.replace(expression, '&') : '';
77
78 var scrubber_url = p.secure_media && p.secure_media.reddit_video && p.secure_media.reddit_video.scrubber_media_url ? p.secure_media.reddit_video.scrubber_media_url.replace(expression, '&') : '';
79
80 var poster_url = p.preview && p.preview.images ? p.preview.images[0].source.url.replace(expression, '&') : '';
81
82 return [hls_url, dash_url, fallback_url, scrubber_url, poster_url];
83 } \ No newline at end of file