Skip to content

Commit eaf66eb

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b034741 + 21eba43 commit eaf66eb

13 files changed

+430
-105
lines changed

Diff for: src/mixins/comment.pug

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include ../utils
2+
include postUtils
23

34
mixin infoContainer(data, next_id, prev_id)
45
- var hats = (data.is_submitter?['op']:[]).concat(data.distinguished=="moderator"?['mod']:[])
@@ -51,7 +52,7 @@ mixin comment(com, isfirst, parent_id, next_id, prev_id)
5152
summary.expand-comments
5253
+infoContainer(data, next_id, prev_id)
5354
div.comment-body
54-
!= data.body_html
55+
!= convertInlineImageLinks(data.body_html)
5556
if hasReplyData
5657
div.replies
5758
- var total = data.replies.data.children.length

Diff for: src/mixins/header.pug

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
mixin header(user)
2+
- var viewQuery = 'view=' + (query && query.view ? query.view : 'compact')
3+
- var sortQuery = 'sort=' + (query ? (query.sort ? query.sort + (query.t ? '&t=' + query.t : '') : 'hot') : 'hot')
24
div.header
35
div.header-item
4-
a(href=`/`) home
6+
a(href=`/?${sortQuery}&${viewQuery}`) home
57
div.header-item
6-
a(href=`/r/all`) all
8+
a(href=`/r/all?${sortQuery}&${viewQuery}`) all
79
div.header-item
8-
a(href=`/search`) search
10+
a(href=`/search?${sortQuery}&${viewQuery}`) search
911
div.header-item
10-
a(href=`/subs`) subs
12+
a(href=`/subs?${sortQuery}&${viewQuery}`) subs
1113
if user
1214
div.header-item
13-
a(href='/dashboard') #{user.username}
15+
a(href=`/dashboard?${sortQuery}&${viewQuery}`) #{user.username}
1416
| 
1517
a(href='/logout') (logout)
1618
else

Diff for: src/mixins/post.pug

+75-42
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ include ../utils
22
include postUtils
33
mixin post(p, currentUrl)
44
- var from = encodeURIComponent(currentUrl)
5-
article(class=`post ${p.stickied?"sticky":""}`)
6-
div.post-container
7-
div.post-text
8-
div.title-container
9-
a(href=`/comments/${p.id}?from=${from}`)
5+
- var viewQuery = query && query.view ? query.view : 'compact'
6+
- var sortQuery = query && query.sort ? query.sort + (query.t ? '&t=' + query.t : '') : 'hot'
7+
article(class=`post`)
8+
div.post-container(class=`${query.view} ${p.stickied?"sticky":""}`)
9+
div.post-text(class=`${query.view}`)
10+
div.title-container(class=`${query.view}`)
11+
a(class=`${query.view}`, href=`/comments/${p.id}?from=${from}&sort=${sortQuery}&view=${viewQuery}`)
1012
!= p.title
1113
span.domain (#{p.domain})
1214
div.info-container
@@ -22,50 +24,81 @@ mixin post(p, currentUrl)
2224
|  · 
2325
| #{timeDifference(Date.now(), p.created * 1000)}
2426
|  · 
25-
a(href=`/r/${p.subreddit}`) r/#{p.subreddit}
27+
a(href=`/r/${p.subreddit}?sort=${sortQuery}&view=${viewQuery}`) r/#{p.subreddit}
2628
|  · 
27-
a(href=`/comments/${p.id}?from=${from}`) #{fmtnum (p.num_comments)}
28-
div.media-preview
29+
a(href=`/comments/${p.id}?from=${from}&sort=${sortQuery}&view=${viewQuery}`) #{fmtnum (p.num_comments)}
30+
if (query.view == "card" && !isPostGallery(p) && !isPostImage(p) && !isPostVideo(p) && p.selftext_html)
31+
div.self-text-overflow(class='card')
32+
if query.view == "card" && (p.spoiler || p.over_18)
33+
div.spoiler(id=`spoiler_${p.id}`, onclick=`javascript:document.getElementById('spoiler_${p.id}').style.display = 'none';`)
34+
h2
35+
!= p.over_18 ? 'nsfw' : 'spoiler'
36+
div.self-text(class='card')
37+
!= convertInlineImageLinks(p.selftext_html)
38+
div.media-preview(class=`${query.view}`)
39+
- var onclick = query.view != "card" ? `toggleDetails('${p.id}')` : ``
40+
if query.view == "card" && (p.spoiler || p.over_18) && (isPostGallery(p) || isPostImage(p) || isPostVideo(p))
41+
div.spoiler(id=`spoiler_${p.id}`, onclick=`javascript:document.getElementById('spoiler_${p.id}').style.display = 'none';`)
42+
h2
43+
!= p.over_18 ? 'nsfw' : 'spoiler'
2944
if isPostGallery(p)
3045
- var item = postGalleryItems(p)[0]
31-
img(src=item.url onclick=`toggleDetails('${p.id}')`)
46+
if query.view == "card"
47+
div.gallery(class=`${query.view}`)
48+
each item in postGalleryItems(p)
49+
div.gallery-item(class=`${query.view}`)
50+
a(href=`/media/${item.url}`)
51+
img(src=item.url loading="lazy")
52+
div.gallery-item-idx(class=`${query.view}`)
53+
| #{`${item.idx}/${item.total}`}
54+
else
55+
img(src=item.url onclick=onclick)
3256
else if isPostImage(p)
33-
- var url = postThumbnail(p)
34-
img(src=url onclick=`toggleDetails('${p.id}')`)
57+
- var url = query.view == "card" ? p.url : postThumbnail(p)
58+
#{query.view == "card" ? "a href=/media/" + url : span}
59+
img(src=url onclick=onclick)
3560
else if isPostVideo(p)
36-
- var url = p.secure_media.reddit_video.scrubber_media_url
37-
video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`)
61+
- var decodedVideos = decodePostVideoUrls(p)
62+
if query.view == "card"
63+
video(controls="" muted="" data-dashjs-player="" preload="metadata" poster=decodedVideos[4])
64+
// HLS
65+
source(src=decodedVideos[0])
66+
// Dash
67+
source(src=decodedVideos[1])
68+
// Fallback
69+
source(src=decodedVideos[2])
70+
else
71+
video(autoplay="" muted="" data-dashjs-player="" onclick=`toggleDetails('${p.id}')` width="100px" height="100px")
72+
// Scrubber
73+
source(src=decodedVideos[3])
3874
else if isPostLink(p)
3975
a(href=p.url)
76+
if (query.view == 'card')
77+
| #{p.domain}
4078
| ↗
4179

42-
if isPostGallery(p)
80+
if query.view == "compact" && (isPostGallery(p) || isPostImage(p) || isPostVideo(p))
4381
details(id=`${p.id}`)
44-
summary.expand-post expand gallery
45-
div.gallery
46-
each item in postGalleryItems(p)
47-
div.gallery-item
48-
div.gallery-item-idx
49-
| #{`${item.idx}/${item.total}`}
50-
a(href=`/media/${item.url}`)
51-
img(src=item.url loading="lazy")
52-
button(onclick=`toggleDetails('${p.id}')`) close
53-
else if isPostImage(p)
54-
details(id=`${p.id}`)
55-
summary.expand-post expand image
56-
a(href=`/media/${p.url}`)
57-
img(src=p.url loading="lazy").post-media
58-
button(onclick=`toggleDetails('${p.id}')`) close
59-
else if isPostVideo(p)
60-
details(id=`${p.id}`)
61-
summary.expand-post expand video
62-
- var url = p.secure_media.reddit_video.dash_url
63-
video(src=url controls data-dashjs-player loading="lazy").post-media
64-
button(onclick=`toggleDetails('${p.id}')`) close
65-
else if isPostLink(p)
66-
details(id=`${p.id}`)
67-
summary.expand-post expand link
68-
a(href=`${p.url}`)
69-
| #{p.url}
70-
br
71-
button(onclick=`toggleDetails('${p.id}')`) close
82+
summary.expand-post expand media
83+
div.image-viewer
84+
if isPostGallery(p)
85+
div.gallery
86+
each item in postGalleryItems(p)
87+
div.gallery-item
88+
div.gallery-item-idx
89+
| #{`${item.idx}/${item.total}`}
90+
a(href=`/media/${item.url}`)
91+
img(src=item.url loading="lazy")
92+
else if isPostImage(p)
93+
a(href=`/media/${p.url}`)
94+
img(src=p.url loading="lazy").post-media
95+
else if isPostVideo(p)
96+
video(controls="" muted="" data-dashjs-player="" preload="metadata" playsinline="" poster=decodedVideos[4] objectfit="contain" loading="lazy").post-media
97+
//HLS
98+
source(src=decodedVideos[0])
99+
// Dash
100+
source(src=decodedVideos[1])
101+
// Fallback
102+
source(src=decodedVideos[2])
103+
button(onclick=`toggleDetails('${p.id}')`)
104+
| close

Diff for: src/mixins/postUtils.pug

+37-6
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
}
1111
-
1212
function postThumbnail(p) {
13-
if (p.thumbnail == "image" || p.thumbnail == "") {
14-
return p.url;
15-
} else if (p.over_18) {
16-
return "/nsfw.svg";
13+
if (p.over_18) {
14+
return "/nsfw.svg";
1715
} 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;
1919
} else {
20-
return p.thumbnail;
20+
return p.thumbnail;
2121
}
2222
}
2323
-
@@ -51,3 +51,34 @@
5151
return null;
5252
}
5353
}
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+
}

0 commit comments

Comments
 (0)