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.pug43
1 files changed, 37 insertions, 6 deletions
diff --git a/src/mixins/postUtils.pug b/src/mixins/postUtils.pug
index 816adf7..b96ff1e 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,34 @@
51 return null; 51 return null;
52 } 52 }
53 } 53 }
54-
55 function convertInlineImageLinks(html) {
56 // Find all anchors that href to preview.redd.it, i.redd.it, i.imgur.com
57 // and contain just a link to the same href
58 const expression = /<a href="(http[s]?:\/\/(?:preview\.redd\.it|i\.redd\.it|i\.imgur\.com).*?)">\1?<\/a>/g;
59 const matches = html.matchAll(expression);
60 var result = html;
61 matches.forEach((match) => {
62 // Replace each occurrence with an actual img tag
63 result = result.replace(match[0], '<a href="' + match[1] + '"><img class="inline" src="' + match[1] + '"></a>');
64 })
65
66 return result;
67 }
68-
69 function decodePostVideoUrls(p) {
70 // Video URLs have querystring separators that are HTML-encoded, so replace them.
71 const expression = /&amp;/g;
72
73 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, '&') : '';
74
75 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, '&') : '';
76
77 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, '&') : '';
78
79 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, '&') : '';
80
81 var poster_url = p.preview && p.preview.images ? p.preview.images[0].source.url.replace(expression, '&') : '';
82
83 return [hls_url, dash_url, fallback_url, scrubber_url, poster_url];
84 } \ No newline at end of file