aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-10-29 20:56:27 +0000
committerAkshay <[email protected]>2024-10-29 20:56:54 +0000
commit33e89cce40a62af327635f4cb32da54c3149e812 (patch)
treefe85506caa2fd9a84fb50c4ce2fb63621f97d8a0 /src
parent93b2f948382d4d50c76b0773fab4c44913a1b2f7 (diff)
improvements to media preview, and galleries
Diffstat (limited to 'src')
-rw-r--r--src/geddit.js2
-rw-r--r--src/mixins/post.pug38
-rw-r--r--src/public/styles.css22
-rw-r--r--src/routes/index.js19
-rw-r--r--src/views/comments.pug3
-rw-r--r--src/views/index.pug13
6 files changed, 80 insertions, 17 deletions
diff --git a/src/geddit.js b/src/geddit.js
index 825c3a9..93477e7 100644
--- a/src/geddit.js
+++ b/src/geddit.js
@@ -14,7 +14,7 @@ class Geddit {
14 14
15 async getSubmissions(sort = null, subreddit = null, options = {}) { 15 async getSubmissions(sort = null, subreddit = null, options = {}) {
16 let params = { 16 let params = {
17 limit: 25, 17 limit: 50,
18 include_over_18: true, 18 include_over_18: true,
19 } 19 }
20 20
diff --git a/src/mixins/post.pug b/src/mixins/post.pug
index cbe2365..fc765ab 100644
--- a/src/mixins/post.pug
+++ b/src/mixins/post.pug
@@ -15,12 +15,40 @@ mixin post(p)
15 div.info-item 15 div.info-item
16 a(href=`/comments/${p.id}`) #{fmtnum (p.num_comments)} #{fmttxt(p.num_comments, 'comment')} 16 a(href=`/comments/${p.id}`) #{fmtnum (p.num_comments)} #{fmttxt(p.num_comments, 'comment')}
17 div.media-preview 17 div.media-preview
18 if p.post_hint == "image" || p.post_hint == "link" 18 if p.is_gallery && p.is_gallery == true
19 if p.gallery_data
20 if p.gallery_data.items
21 - var item = p.gallery_data.items[0]
22 - var url = `https://i.redd.it/${item.media_id}.jpg`
23 img(src=url width='100px' height='100px' onclick=`toggleDetails('${p.id}')`)
24 else if p.post_hint == "image" || p.post_hint == "link"
19 if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default" 25 if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default"
20 a(href=p.url) 26 img(src=p.thumbnail width='100px' height='100px' onclick=`toggleDetails('${p.id}')`)
21 img(src=p.thumbnail width='100px' height='100px')
22 else if p.post_hint == "hosted:video" 27 else if p.post_hint == "hosted:video"
23 - var url = p.secure_media.reddit_video.dash_url 28 - var url = p.secure_media.reddit_video.dash_url
24 a(href=url) 29 video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`)
25 video(src=url controls data-dashjs-player="" width='100px' height='100px') 30
31 if p.is_gallery && p.is_gallery == true
32 if p.gallery_data
33 if p.gallery_data.items
34 details(id=`${p.id}`)
35 summary expand gallery
36 each item in p.gallery_data.items
37 - var url = `https://i.redd.it/${item.media_id}.jpg`
38 a(href=`/media/${url}`)
39 img(src=url).post-media
40 button(onclick=`toggleDetails('${p.id}')`) close
41 if (p.post_hint == "image" || p.post_hint == "link") && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default"
42 details(id=`${p.id}`)
43 summary expand image
44 a(href=`/media/${p.url}`)
45 img(src=p.url).post-media
46 button(onclick=`toggleDetails('${p.id}')`) close
47 else if p.post_hint == "hosted:video"
48 details(id=`${p.id}`)
49 summary expand video
50 - var url = p.secure_media.reddit_video.dash_url
51 a(href=url)
52 video(src=url controls data-dashjs-player).post-media
53 button(onclick=`toggleDetails('${p.id}')`) close
26 54
diff --git a/src/public/styles.css b/src/public/styles.css
index 385b341..0d0998d 100644
--- a/src/public/styles.css
+++ b/src/public/styles.css
@@ -60,7 +60,7 @@ nav {
60@media (min-width: 768px) { 60@media (min-width: 768px) {
61 .post, .comments-container, .hero, .header { 61 .post, .comments-container, .hero, .header {
62 flex: 1 1 65%; 62 flex: 1 1 65%;
63 width: 65%; 63 width: 75%;
64 } 64 }
65 .info-container, .comment-info-container { 65 .info-container, .comment-info-container {
66 font-size: 0.8rem; 66 font-size: 0.8rem;
@@ -121,6 +121,10 @@ nav {
121 margin-left: auto; 121 margin-left: auto;
122} 122}
123 123
124.media-preview img {
125 object-fit: cover;
126}
127
124.post-media { 128.post-media {
125 display: block; 129 display: block;
126 margin: 0 auto; 130 margin: 0 auto;
@@ -143,10 +147,6 @@ nav {
143 color: #999; 147 color: #999;
144} 148}
145 149
146.comment-info-container {
147 margin-bottom: -12px;
148}
149
150hr { 150hr {
151 border 1px solid #000; 151 border 1px solid #000;
152} 152}
@@ -171,3 +171,15 @@ pre {
171code { 171code {
172 overflow-x: auto; 172 overflow-x: auto;
173} 173}
174
175p {
176 margin-top: 5px;
177}
178
179.comment-body {
180 text-align: left;
181}
182
183summary {
184 display: none;
185}
diff --git a/src/routes/index.js b/src/routes/index.js
index f43ee6f..867a223 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -11,10 +11,14 @@ router.get('/', async (req, res) => {
11}); 11});
12 12
13// GET /r/:id 13// GET /r/:id
14router.get('/r/:subreddit', async (req, res) => { 14router.get('/r/:subreddit/:sort?', async (req, res) => {
15 var subreddit = req.params.subreddit; 15 var subreddit = req.params.subreddit;
16 var query = req.query;
17 var sort = req.params.sort ? req.params.sort : 'hot';
18 var options = req.query;
16 19
17 var postsReq = G.getSubmissions(`r/${subreddit}`); 20 // var postsReq = G.getSubmissions(sort, `r/${subreddit}`, options);
21 var postsReq = G.getSubmissions(sort, `${subreddit}`, options);
18 var aboutReq = G.getSubreddit(`${subreddit}`); 22 var aboutReq = G.getSubreddit(`${subreddit}`);
19 23
20 var [posts, about] = await Promise.all([postsReq, aboutReq]); 24 var [posts, about] = await Promise.all([postsReq, aboutReq]);
@@ -36,6 +40,17 @@ router.get('/subs', async (req, res) => {
36 res.render('subs'); 40 res.render('subs');
37}); 41});
38 42
43// GET /media
44router.get('/media/*', async (req, res) => {
45 var url = req.params[0];
46 console.log(`making request to ${url}`);
47 return await fetch(url, {
48 headers: {
49 Accept: "*/*",
50 }
51 });
52});
53
39module.exports = router; 54module.exports = router;
40 55
41function unescape_submission(response) { 56function unescape_submission(response) {
diff --git a/src/views/comments.pug b/src/views/comments.pug
index 2b2b76e..7bd1f9e 100644
--- a/src/views/comments.pug
+++ b/src/views/comments.pug
@@ -10,8 +10,7 @@ html
10 body 10 body
11 main#content 11 main#content
12 div.hero 12 div.hero
13 a(href=`/r/${post.subreddit}`) 13 h4 r/#{post.subreddit}
14 h4 ← r/#{post.subreddit}
15 h2 #{post.title} 14 h2 #{post.title}
16 15
17 if post.post_hint == 'image' 16 if post.post_hint == 'image'
diff --git a/src/views/index.pug b/src/views/index.pug
index 8bbef65..9ac34a4 100644
--- a/src/views/index.pug
+++ b/src/views/index.pug
@@ -27,6 +27,13 @@ html
27 b.appendChild(button); 27 b.appendChild(button);
28 } 28 }
29 29
30 function toggleDetails(details_id) {
31 var detailsElement = document.getElementById(details_id);
32 if (detailsElement) {
33 detailsElement.open = !detailsElement.open;
34 }
35 }
36
30 document.addEventListener('DOMContentLoaded', ()=>updateButton("#{subreddit}")); 37 document.addEventListener('DOMContentLoaded', ()=>updateButton("#{subreddit}"));
31 body 38 body
32 main#content 39 main#content
@@ -44,8 +51,10 @@ html
44 if about 51 if about
45 p #{about.public_description} 52 p #{about.public_description}
46 div#button-container 53 div#button-container
54 a(href=`/r/${subreddit}`)
47 55
48 each child in posts.posts 56 if posts
49 +post(child.data) 57 each child in posts.posts
58 +post(child.data)
50 59
51 script(src='https://unpkg.com/[email protected]') 60 script(src='https://unpkg.com/[email protected]')