aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.nix1
-rw-r--r--src/routes/index.js41
-rw-r--r--src/views/post-search.pug23
-rw-r--r--src/views/search.pug54
-rw-r--r--src/views/sub-search.pug4
5 files changed, 120 insertions, 3 deletions
diff --git a/flake.nix b/flake.nix
index 759e670..b7fafae 100644
--- a/flake.nix
+++ b/flake.nix
@@ -103,6 +103,7 @@
103 nativeBuildInputs = [ 103 nativeBuildInputs = [
104 pkgs.bun 104 pkgs.bun
105 pkgs.biome 105 pkgs.biome
106 pkgs.typescript-language-server
106 ]; 107 ];
107 }); 108 });
108 109
diff --git a/src/routes/index.js b/src/routes/index.js
index 0dafd3e..604cabb 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -102,8 +102,13 @@ router.get("/subs", authenticateToken, async (req, res) => {
102 res.render("subs", { subs, user: req.user }); 102 res.render("subs", { subs, user: req.user });
103}); 103});
104 104
105// GET /search-subreddits 105// GET /search
106router.get("/search", authenticateToken, async (req, res) => { 106router.get("/search", authenticateToken, async (req, res) => {
107 res.render("search", { user: req.user });
108});
109
110// GET /sub-search
111router.get("/sub-search", authenticateToken, async (req, res) => {
107 if (!req.query || !req.query.q) { 112 if (!req.query || !req.query.q) {
108 res.render("sub-search", { user: req.user }); 113 res.render("sub-search", { user: req.user });
109 } else { 114 } else {
@@ -141,6 +146,40 @@ router.get("/search", authenticateToken, async (req, res) => {
141 } 146 }
142}); 147});
143 148
149// GET /post-search
150router.get("/post-search", authenticateToken, async (req, res) => {
151 if (!req.query || !req.query.q) {
152 res.render("post-search", { user: req.user });
153 } else {
154 const { q, options } = req.query.q.split(/\s+/).reduce(
155 (acc, word) => {
156 if (word.startsWith("+")) {
157 acc.options.push(word.slice(1));
158 } else {
159 acc.q += `${word} `;
160 }
161 return acc;
162 },
163 { options: [], q: "" },
164 );
165
166 const { items, after } = await G.searchSubmissions(q, {
167 include_over_18: options.includes("nsfw"),
168 });
169 const message =
170 items.length === 0
171 ? "no results found"
172 : `showing ${items.length} results`;
173 res.render("post-search", {
174 items,
175 after,
176 message,
177 user: req.user,
178 original_query: req.query.q,
179 });
180 }
181});
182
144// GET /dashboard 183// GET /dashboard
145router.get("/dashboard", authenticateToken, async (req, res) => { 184router.get("/dashboard", authenticateToken, async (req, res) => {
146 let invites = null; 185 let invites = null;
diff --git a/src/views/post-search.pug b/src/views/post-search.pug
new file mode 100644
index 0000000..441d939
--- /dev/null
+++ b/src/views/post-search.pug
@@ -0,0 +1,23 @@
1include ../mixins/post
2include ../mixins/header
3include ../mixins/head
4
5doctype html
6html
7 +head("search posts")
8 include ../mixins/subUtils
9 body
10 main#content
11 +header(user)
12 div.hero
13 h1 search posts
14 form(action="/post-search" method="get").search-bar
15 - var prefill = original_query ?? "";
16 input(type="text" name="q" placeholder="search posts" value=prefill required).search-input
17 button(type="submit").search-button go
18 if message
19 div.search-message
20 i #{message}
21 if items
22 each item in items
23 +post(item.data)
diff --git a/src/views/search.pug b/src/views/search.pug
new file mode 100644
index 0000000..216875f
--- /dev/null
+++ b/src/views/search.pug
@@ -0,0 +1,54 @@
1include ../mixins/header
2include ../mixins/head
3
4doctype html
5html
6 +head("search subreddits")
7 include ../mixins/subUtils
8 body
9 main#content
10 +header(user)
11 div.hero
12 h1 search subreddits
13
14 form(action="/sub-search" method="get").search-bar
15 - var prefill = original_query ?? "";
16 input(type="text" name="q" placeholder="search subreddits" value=prefill required).search-input
17 button(type="submit").search-button go
18
19 h1 search posts
20
21 form(action="/post-search" method="get").search-bar
22 - var prefill = original_query ?? "";
23 input(type="text" name="q" placeholder="search posts" value=prefill required).search-input
24 button(type="submit").search-button go
25
26 hr
27
28 h3 tips
29 p
30 | you can narrow search results using filters:
31 br
32 -
33 var triples = [
34 ["subreddit", "ohio", "find submissions in 'r/ohio'"],
35 ["author", "spez", "find submissions by 'u/spez'"],
36 ["site", "x.com", "find submissions from 'x.com'"],
37 ["url", "text", "search for 'text' in url"],
38 ["selftext", "text", "search for 'text' in post contents"],
39 ["self", "yes/no", "include/exclude selftext posts"],
40 ["nsfw", "yes/no", "include/exclude over-18 posts"],
41 ]
42
43 ul
44 each triple in triples
45 li
46 strong
47 | #{triple[0]}:
48 em #{triple[1]}
49 |     #{triple[2]}
50 | example:
51 br
52 |    
53 code subreddit:iowa site:x.com elections
54
diff --git a/src/views/sub-search.pug b/src/views/sub-search.pug
index bf0d402..76d72a8 100644
--- a/src/views/sub-search.pug
+++ b/src/views/sub-search.pug
@@ -10,9 +10,9 @@ html
10 +header(user) 10 +header(user)
11 div.hero 11 div.hero
12 h1 search subreddits 12 h1 search subreddits
13 form(action="/search" method="get").search-bar 13 form(action="/sub-search" method="get").search-bar
14 - var prefill = original_query ?? ""; 14 - var prefill = original_query ?? "";
15 input(type="text" name="q" placeholder="search subreddits (add +nsfw to include over-18 results)" value=prefill required).search-input 15 input(type="text" name="q" placeholder="search subreddits" value=prefill required).search-input
16 button(type="submit").search-button go 16 button(type="submit").search-button go
17 if message 17 if message
18 div.search-message 18 div.search-message