aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-02 12:47:59 +0000
committerAkshay <[email protected]>2024-11-02 12:47:59 +0000
commit0d0cfdd280379ea1799cd423ad15392d417fcfb7 (patch)
tree3d787ec1251130f2dd38ea8d4b240f6379328eb8 /src
parentbd78cbc3642d9495c407e15ac955a2d8efd5a69e (diff)
add dark mode, add time for comments and posts
Diffstat (limited to 'src')
-rw-r--r--src/mixins/comment.pug1
-rw-r--r--src/mixins/post.pug20
-rw-r--r--src/public/styles.css88
-rw-r--r--src/utils.pug27
-rw-r--r--src/views/comments.pug19
5 files changed, 128 insertions, 27 deletions
diff --git a/src/mixins/comment.pug b/src/mixins/comment.pug
index 8d341c9..2ec076f 100644
--- a/src/mixins/comment.pug
+++ b/src/mixins/comment.pug
@@ -13,6 +13,7 @@ mixin comment(com, isfirst)
13 if data.collapsed_reason_code == "DELETED" 13 if data.collapsed_reason_code == "DELETED"
14 div.info-item 14 div.info-item
15 a(href=`https://undelete.pullpush.io${data.permalink}`) search on undelete 15 a(href=`https://undelete.pullpush.io${data.permalink}`) search on undelete
16 div.info-item #{timeDifference(Date.now(), data.created * 1000)}
16 div.comment-body 17 div.comment-body
17 != data.body_html 18 != data.body_html
18 div.replies 19 div.replies
diff --git a/src/mixins/post.pug b/src/mixins/post.pug
index 3e7e51a..9dd0748 100644
--- a/src/mixins/post.pug
+++ b/src/mixins/post.pug
@@ -14,6 +14,8 @@ mixin post(p)
14 | &nbsp;·&nbsp; 14 | &nbsp;·&nbsp;
15 by u/#{p.author} 15 by u/#{p.author}
16 | &nbsp;·&nbsp; 16 | &nbsp;·&nbsp;
17 | #{timeDifference(Date.now(), p.created * 1000)}
18 | &nbsp;·&nbsp;
17 a(href=`/r/${p.subreddit}`) r/#{p.subreddit} 19 a(href=`/r/${p.subreddit}`) r/#{p.subreddit}
18 | &nbsp;·&nbsp; 20 | &nbsp;·&nbsp;
19 a(href=`/comments/${p.id}`) #{fmtnum (p.num_comments)} ↩ 21 a(href=`/comments/${p.id}`) #{fmtnum (p.num_comments)} ↩
@@ -28,7 +30,7 @@ mixin post(p)
28 if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default" 30 if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default"
29 img(src=p.thumbnail onclick=`toggleDetails('${p.id}')`) 31 img(src=p.thumbnail onclick=`toggleDetails('${p.id}')`)
30 else if p.post_hint == "hosted:video" 32 else if p.post_hint == "hosted:video"
31 - var url = p.secure_media.reddit_video.dash_url 33 - var url = p.secure_media.reddit_video.scrubber_media_url
32 video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`) 34 video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`)
33 35
34 if p.is_gallery && p.is_gallery == true 36 if p.is_gallery && p.is_gallery == true
@@ -37,23 +39,31 @@ mixin post(p)
37 details(id=`${p.id}`) 39 details(id=`${p.id}`)
38 summary expand gallery 40 summary expand gallery
39 div.gallery 41 div.gallery
42 - var total = p.gallery_data.items.length
43 - var idx = 0
44 - var metadata = p.media_metadata
45 - var img_ext = (id) => stripPrefix(metadata[id].m, "image/")
40 each item in p.gallery_data.items 46 each item in p.gallery_data.items
41 - var url = `https://i.redd.it/${item.media_id}.jpg` 47 - var id = item.media_id
48 - var ext = img_ext(item.media_id)
49 - var url = `https://i.redd.it/${id}.${ext}`
42 div.gallery-item 50 div.gallery-item
43 a(href=`/media/${url}`) 51 a(href=`/media/${url}`)
44 img(src=url) 52 img(src=url loading="lazy")
53 div.gallery-item-idx
54 | #{`${++idx}/${total}`}
45 button(onclick=`toggleDetails('${p.id}')`) close 55 button(onclick=`toggleDetails('${p.id}')`) close
46 if p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default" 56 if p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default"
47 details(id=`${p.id}`) 57 details(id=`${p.id}`)
48 summary expand image 58 summary expand image
49 a(href=`/media/${p.url}`) 59 a(href=`/media/${p.url}`)
50 img(src=p.url).post-media 60 img(src=p.url loading="lazy").post-media
51 button(onclick=`toggleDetails('${p.id}')`) close 61 button(onclick=`toggleDetails('${p.id}')`) close
52 else if p.post_hint == "hosted:video" 62 else if p.post_hint == "hosted:video"
53 details(id=`${p.id}`) 63 details(id=`${p.id}`)
54 summary expand video 64 summary expand video
55 - var url = p.secure_media.reddit_video.dash_url 65 - var url = p.secure_media.reddit_video.dash_url
56 video(src=url controls data-dashjs-player).post-media 66 video(src=url controls data-dashjs-player loading="lazy").post-media
57 button(onclick=`toggleDetails('${p.id}')`) close 67 button(onclick=`toggleDetails('${p.id}')`) close
58 else if p.post_hint == "link" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default" 68 else if p.post_hint == "link" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default"
59 details(id=`${p.id}`) 69 details(id=`${p.id}`)
diff --git a/src/public/styles.css b/src/public/styles.css
index 3a0cb8b..b9da7a1 100644
--- a/src/public/styles.css
+++ b/src/public/styles.css
@@ -1,8 +1,32 @@
1@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap'); 1@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
2 2
3:root {
4 /* Light mode colors */
5 --bg-color: white;
6 --text-color: black;
7 --text-color-muted: #999;
8 --blockquote-color: green;
9 --link-color: blue;
10 --link-visited-color: purple;
11}
12
13@media (prefers-color-scheme: dark) {
14 :root {
15 --bg-color: black;
16 --text-color: white;
17 --text-color-muted: #999;
18 --blockquote-color: green;
19 --link-color: lightblue;
20 --link-visited-color: violet;
21 }
22}
23
24
3body { 25body {
4 font-family: 'Inter', sans-serif; 26 font-family: 'Inter', sans-serif;
5 overflow-x: hidden; 27 overflow-x: hidden;
28 background-color: var(--bg-color);
29 color: var(--text-color);
6} 30}
7 31
8main { 32main {
@@ -12,6 +36,20 @@ main {
12 align-items: center; 36 align-items: center;
13} 37}
14 38
39a {
40 color: var(--link-color);
41 text-decoration: none;
42}
43
44a:hover {
45 color: var(--link-color);
46 text-decoration: underline;
47}
48
49a:visited {
50 color: var(--link-visited-color);
51}
52
15.header { 53.header {
16 display: flex; 54 display: flex;
17 flex-direction: row; 55 flex-direction: row;
@@ -38,7 +76,7 @@ nav {
38 width: 100%; 76 width: 100%;
39} 77}
40 78
41.post { 79.post, .hero {
42 font-size: 1rem; 80 font-size: 1rem;
43} 81}
44 82
@@ -46,14 +84,21 @@ nav {
46 font-size: 1rem; 84 font-size: 1rem;
47} 85}
48 86
87.info-container a,
88.info-container,
89.comment-info-container,
90.more,
91hr {
92 color: var(--text-color-muted)
93}
94
49.info-container, .comment-info-container, .more { 95.info-container, .comment-info-container, .more {
50 color: #777;
51 font-size: 0.8rem; 96 font-size: 0.8rem;
52 display: flex; 97 display: flex;
53} 98}
54 99
55.domain { 100.domain {
56 color: #777; 101 color: var(--text-color-muted);
57 font-size: 0.8rem; 102 font-size: 0.8rem;
58} 103}
59 104
@@ -62,7 +107,8 @@ nav {
62} 107}
63 108
64 109
65.media-preview img { 110.media-preview img,
111.media-preview video {
66 object-fit: cover; 112 object-fit: cover;
67} 113}
68 114
@@ -81,11 +127,11 @@ nav {
81 flex: 1 1 90%; 127 flex: 1 1 90%;
82 width: 90%; 128 width: 90%;
83 } 129 }
84 .post { 130 .post, .hero {
85 font-size: 1.3rem; 131 font-size: 1.3rem;
86 } 132 }
87 .comments-container { 133 .comments-container {
88 font-size: 1.1rem; 134 font-size: 1.3rem;
89 } 135 }
90 .info-container, .comment-info-container, .more { 136 .info-container, .comment-info-container, .more {
91 font-size: 1rem; 137 font-size: 1rem;
@@ -106,14 +152,14 @@ nav {
106 152
107@media (min-width: 1080px) { 153@media (min-width: 1080px) {
108 .post, .comments-container, .hero, .header, .footer { 154 .post, .comments-container, .hero, .header, .footer {
109 flex: 1 1 50%; 155 flex: 1 1 60%;
110 width: 50%; 156 width: 60%;
111 } 157 }
112 .post { 158 .post, .hero {
113 font-size: 1.3rem; 159 font-size: 1.3rem;
114 } 160 }
115 .comments-container { 161 .comments-container {
116 font-size: 1.1rem; 162 font-size: 1.3rem;
117 } 163 }
118 .info-container, .comment-info-container, .more { 164 .info-container, .comment-info-container, .more {
119 font-size: 1rem; 165 font-size: 1rem;
@@ -138,7 +184,7 @@ nav {
138 184
139.comment, .more { 185.comment, .more {
140 width: 100%; 186 width: 100%;
141 border-left: 1px dashed; 187 border-left: 1px dashed var(--text-color-muted);
142 padding: 10px 0px 0px 24px; 188 padding: 10px 0px 0px 24px;
143 box-sizing: border-box; 189 box-sizing: border-box;
144} 190}
@@ -149,7 +195,6 @@ nav {
149 195
150.more { 196.more {
151 margin-bottom: 0px; 197 margin-bottom: 0px;
152 color: #777;
153} 198}
154 199
155.first { 200.first {
@@ -189,19 +234,27 @@ nav {
189 padding: 5px; 234 padding: 5px;
190} 235}
191 236
192.title-container,.info-container, .comment-info-container { 237.title-container, .comment-info-container {
193 flex: 1; 238 flex: 1;
194 margin-top: 10px; 239 margin-top: 10px;
195 margin-bottom: 10px; 240 margin-bottom: 10px;
196} 241}
197 242
243.info-container {
244 flex: 1;
245}
246
198.title-container > a { 247.title-container > a {
199 color: black; 248 color: var(--text-color);
200 text-decoration: none; 249 text-decoration: none;
201} 250}
202 251
203.title-container > a:visited { 252.title-container > a:visited {
204 color: #999; 253 color: var(--text-color-muted)
254}
255
256.header a {
257 color: var(--text-color);
205} 258}
206 259
207hr { 260hr {
@@ -211,8 +264,8 @@ hr {
211blockquote { 264blockquote {
212 margin: 0px; 265 margin: 0px;
213 padding-left: 10px; 266 padding-left: 10px;
214 border-left: 4px solid green; 267 border-left: 4px solid var(--blockquote-color);
215 color: green; 268 color: var(--blockquote-color);
216} 269}
217 270
218pre, code { 271pre, code {
@@ -254,6 +307,7 @@ a {
254.gallery { 307.gallery {
255 display: flex; 308 display: flex;
256 overflow-x: auto; 309 overflow-x: auto;
310 position: relative;
257 scroll-snap-type: x mandatory; 311 scroll-snap-type: x mandatory;
258 padding: 5px; 312 padding: 5px;
259} 313}
diff --git a/src/utils.pug b/src/utils.pug
index f3f61bb..81cf3f7 100644
--- a/src/utils.pug
+++ b/src/utils.pug
@@ -1,3 +1,28 @@
1- var fmtnum = (n)=>n>=1000?(n/1000).toFixed(1)+'k':n; 1- var fmtnum = (n)=>n>=1000?(n/1000).toFixed(1)+'k':n;
2- var fmttxt = (n,t)=>`${t}${n==1?'':'s'}` 2- var fmttxt = (n,t)=>`${t}${n==1?'':'s'}`
3 3- var stripPrefix = (s, p) => s.startsWith(p) ? s.slice(p.length) : s;
4-
5 function timeDifference(current, previous) {
6 if (!current || !previous) {
7 return '';
8 }
9 var msPerMinute = 60 * 1000;
10 var msPerHour = msPerMinute * 60;
11 var msPerDay = msPerHour * 24;
12 var msPerMonth = msPerDay * 30;
13 var msPerYear = msPerDay * 365;
14 var elapsed = current - previous;
15 if (elapsed < msPerMinute) {
16 return Math.round(elapsed/1000) + 's';
17 } else if (elapsed < msPerHour) {
18 return Math.round(elapsed/msPerMinute) + 'min';
19 } else if (elapsed < msPerDay ) {
20 return Math.round(elapsed/msPerHour ) + 'h';
21 } else if (elapsed < msPerMonth) {
22 return Math.round(elapsed/msPerDay) + 'd';
23 } else if (elapsed < msPerYear) {
24 return Math.round(elapsed/msPerMonth) + 'mo';
25 } else {
26 return Math.round(elapsed/msPerYear ) + 'y';
27 }
28 }
diff --git a/src/views/comments.pug b/src/views/comments.pug
index d7a8ab4..9d02a01 100644
--- a/src/views/comments.pug
+++ b/src/views/comments.pug
@@ -21,17 +21,28 @@ html
21 if post.is_gallery && post.is_gallery == true 21 if post.is_gallery && post.is_gallery == true
22 if post.gallery_data 22 if post.gallery_data
23 if post.gallery_data.items 23 if post.gallery_data.items
24 each item in post.gallery_data.items 24 div.gallery
25 - var url = `https://i.redd.it/${item.media_id}.jpg` 25 - var total = post.gallery_data.items.length
26 img(src=url).post-media 26 - var idx = 0
27 if (post.post_hint == "image" || post.post_hint == "link") && post.thumbnail && post.thumbnail != "self" && post.thumbnail != "default" 27 each item in post.gallery_data.items
28 - var url = `https://i.redd.it/${item.media_id}.jpg`
29 div.gallery-item
30 a(href=`/media/${url}`)
31 img(src=url loading="lazy")
32 div.gallery-item-idx
33 | #{`${++idx}/${total}`}
34 else if post.post_hint == "image" && post.thumbnail && post.thumbnail != "self" && post.thumbnail != "default"
28 img(src=post.url).post-media 35 img(src=post.url).post-media
29 else if post.post_hint == 'hosted:video' 36 else if post.post_hint == 'hosted:video'
30 - var url = post.secure_media.reddit_video.dash_url 37 - var url = post.secure_media.reddit_video.dash_url
31 video(controls data-dashjs-player src=`${url}`).post-media 38 video(controls data-dashjs-player src=`${url}`).post-media
39 else if post.post_hint == "link" && post.thumbnail && post.thumbnail != "self" && post.thumbnail != "default"
40 a(href=`${post.url}`)
41 | #{post.url}
32 42
33 if post.selftext_html 43 if post.selftext_html
34 p.self-text !{post.selftext_html} 44 p.self-text !{post.selftext_html}
45
35 div.info-container 46 div.info-container
36 p 47 p
37 | #{fmtnum(post.ups)} ↑ 48 | #{fmtnum(post.ups)} ↑