aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-05 22:44:56 +0000
committerAkshay <[email protected]>2024-11-05 22:44:56 +0000
commit47b4fd3b1233353e56c99c0b9a5a8633d8bc2617 (patch)
treee189fc34780bd67146bb6301dd28b4f803405b7f
parentf1bf73b65a29cb733651b1c990e27f84769dc5c3 (diff)
subs as home page
-rw-r--r--readme.txt4
-rw-r--r--src/mixins/header.pug4
-rw-r--r--src/mixins/post.pug7
-rw-r--r--src/public/styles.css7
-rw-r--r--src/routes/index.js5
-rw-r--r--src/views/home.pug13
-rw-r--r--src/views/index.pug13
7 files changed, 36 insertions, 17 deletions
diff --git a/readme.txt b/readme.txt
index 7a152b3..dc6971a 100644
--- a/readme.txt
+++ b/readme.txt
@@ -15,5 +15,5 @@ todo:
15- [ ] highlights for op, sticky etc. 15- [ ] highlights for op, sticky etc.
16- [ ] support 'more comments' 16- [ ] support 'more comments'
17- [ ] avoid js to toggle details in views/index.pug 17- [ ] avoid js to toggle details in views/index.pug
18- [ ] set home to sum of subs 18- [x] set home to sum of subs
19- [ ] details tag on safari 19- [x] details tag on safari
diff --git a/src/mixins/header.pug b/src/mixins/header.pug
index e3b3870..f4b85e0 100644
--- a/src/mixins/header.pug
+++ b/src/mixins/header.pug
@@ -3,7 +3,9 @@ mixin header()
3 div.header-item 3 div.header-item
4 a(href=`/`) home 4 a(href=`/`) home
5 div.header-item 5 div.header-item
6 a(href=`/subs`) subscriptions 6 a(href=`/r/all`) all
7 div.header-item 7 div.header-item
8 a(href=`/r/popular`) popular 8 a(href=`/r/popular`) popular
9 div.header-item
10 a(href=`/subs`) subscriptions
9 11
diff --git a/src/mixins/post.pug b/src/mixins/post.pug
index 8cec398..43a3eb8 100644
--- a/src/mixins/post.pug
+++ b/src/mixins/post.pug
@@ -26,9 +26,8 @@ mixin post(p)
26 - var item = p.gallery_data.items[0] 26 - var item = p.gallery_data.items[0]
27 - var url = `https://i.redd.it/${item.media_id}.jpg` 27 - var url = `https://i.redd.it/${item.media_id}.jpg`
28 img(src=url onclick=`toggleDetails('${p.id}')`) 28 img(src=url onclick=`toggleDetails('${p.id}')`)
29 else if p.post_hint == "image" || p.post_hint == "link" 29 else if p.post_hint == "image" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default"
30 if p.thumbnail && p.thumbnail != "self" || p.thumbnail != "default" 30 img(src=p.thumbnail onclick=`toggleDetails('${p.id}')`)
31 img(src=p.thumbnail onclick=`toggleDetails('${p.id}')`)
32 else if p.post_hint == "hosted:video" 31 else if p.post_hint == "hosted:video"
33 - var url = p.secure_media.reddit_video.scrubber_media_url 32 - var url = p.secure_media.reddit_video.scrubber_media_url
34 video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`) 33 video(src=url data-dashjs-player width='100px' height='100px' onclick=`toggleDetails('${p.id}')`)
@@ -76,7 +75,7 @@ mixin post(p)
76 - var url = p.secure_media.reddit_video.dash_url 75 - var url = p.secure_media.reddit_video.dash_url
77 video(src=url controls data-dashjs-player loading="lazy").post-media 76 video(src=url controls data-dashjs-player loading="lazy").post-media
78 button(onclick=`toggleDetails('${p.id}')`) close 77 button(onclick=`toggleDetails('${p.id}')`) close
79 else if !p.post_hint || (p.post_hint == "link" && p.thumbnail && p.thumbnail != "self" && p.thumbnail != "default") 78 else if !p.selftext
80 details(id=`${p.id}`) 79 details(id=`${p.id}`)
81 summary.expand-post expand link 80 summary.expand-post expand link
82 a(href=`${p.url}`) 81 a(href=`${p.url}`)
diff --git a/src/public/styles.css b/src/public/styles.css
index 70a6518..14f093b 100644
--- a/src/public/styles.css
+++ b/src/public/styles.css
@@ -431,8 +431,9 @@ a {
431} 431}
432 432
433button { 433button {
434 border: 1px solid var(--text-color-muted); 434 border: 0px solid;
435 border-radius: 4px; 435 border-radius: 4px;
436 background-color: var(--black); 436 background-color: var(--bg-color-muted);
437 color: var(--white); 437 color: var(--text-color);
438 padding: 5px;
438} 439}
diff --git a/src/routes/index.js b/src/routes/index.js
index f60fd96..7fe9e2a 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -6,12 +6,13 @@ const G = new geddit.Geddit();
6 6
7// GET / 7// GET /
8router.get("/", async (req, res) => { 8router.get("/", async (req, res) => {
9 res.redirect("/r/all"); 9 res.render("home");
10}); 10});
11 11
12// GET /r/:id 12// GET /r/:id
13router.get("/r/:subreddit", async (req, res) => { 13router.get("/r/:subreddit", async (req, res) => {
14 const subreddit = req.params.subreddit; 14 const subreddit = req.params.subreddit;
15 const isMulti = subreddit.includes("+");
15 const query = req.query ? req.query : {}; 16 const query = req.query ? req.query : {};
16 if (!query.sort) { 17 if (!query.sort) {
17 query.sort = "hot"; 18 query.sort = "hot";
@@ -22,7 +23,7 @@ router.get("/r/:subreddit", async (req, res) => {
22 23
23 const [posts, about] = await Promise.all([postsReq, aboutReq]); 24 const [posts, about] = await Promise.all([postsReq, aboutReq]);
24 25
25 res.render("index", { subreddit, posts, about, query }); 26 res.render("index", { subreddit, posts, about, query, isMulti });
26}); 27});
27 28
28// GET /comments/:id 29// GET /comments/:id
diff --git a/src/views/home.pug b/src/views/home.pug
new file mode 100644
index 0000000..87f6e0a
--- /dev/null
+++ b/src/views/home.pug
@@ -0,0 +1,13 @@
1include ../mixins/sub
2doctype html
3html
4 +subMgmt()
5 script(async).
6 window.addEventListener("load", () => {
7 const url = `/r/${getSubs().join('+')}`;
8 if (url) {
9 window.location.href = url;
10 } else {
11 window.location.href = '/r/all';
12 }
13 });
diff --git a/src/views/index.pug b/src/views/index.pug
index add4c8e..f7f67b9 100644
--- a/src/views/index.pug
+++ b/src/views/index.pug
@@ -8,7 +8,7 @@ doctype html
8html 8html
9 +head() 9 +head()
10 +subMgmt() 10 +subMgmt()
11 script. 11 script(defer).
12 function updateButton(sub) { 12 function updateButton(sub) {
13 var b = document.getElementById("button-container"); 13 var b = document.getElementById("button-container");
14 b.innerHTML = ''; 14 b.innerHTML = '';
@@ -36,13 +36,16 @@ html
36 body 36 body
37 main#content 37 main#content
38 +header() 38 +header()
39
40 div.hero 39 div.hero
41 div.sub-title 40 div.sub-title
42 h1 41 h1
43 a(href=`/r/${subreddit}`) 42 if isMulti
44 | r/#{subreddit} 43 a(href=`/`) readit
45 div#button-container 44 else
45 a(href=`/r/${subreddit}`)
46 | r/#{subreddit}
47 if !isMulti
48 div#button-container
46 if about 49 if about
47 p #{about.public_description} 50 p #{about.public_description}
48 details 51 details