commit 3431171

default  ·  2024-05-15 03:57:21 +0000 UTC
parent 281f934
User search can also be done by tag.
2 files changed,  +39, -20
M html.c
M html.c
+38, -19
 1@@ -748,7 +748,7 @@ static xs_html *html_user_body(snac *user, int read_only)
 2                     xs_html_sctag("input",
 3                         xs_html_attr("type", "text"),
 4                         xs_html_attr("name", "q"),
 5-                        xs_html_attr("title", L("Search posts by content (regular expression)")),
 6+                        xs_html_attr("title", L("Search posts by content (regular expression) or #tag")),
 7                         xs_html_attr("placeholder", L("Content search")))));
 8     }
 9 
10@@ -2588,25 +2588,44 @@ int html_get_handler(const xs_dict *req, const char *q_path,
11             char *q = xs_dict_get(q_vars, "q");
12 
13             if (q && *q) {
14-                /** search by content **/
15-                int to = 0;
16-                int msecs = atoi(xs_dict_get_def(q_vars, "msecs", "0"));
17-                xs *tl = content_search(&snac, q, 1, skip, show, msecs, &to);
18-                xs *title = NULL;
19-                xs *page = xs_fmt("/admin?q=%s&msecs=%d", q, msecs + 10);
20-                int tl_len = xs_list_len(tl);
21-
22-                if (tl_len)
23-                    title = xs_fmt(L("Search results for '%s'"), q);
24-                else
25-                if (skip)
26-                    title = xs_fmt(L("No more matches for '%s'"), q);
27-                else
28-                    title = xs_fmt(L("Nothing found for '%s'"), q);
29+                if (*q == '#') {
30+                    /** search by tag **/
31+                    xs *tl = tag_search(q, skip, show + 1);
32+                    int more = 0;
33+                    if (xs_list_len(tl) >= show + 1) {
34+                        /* drop the last one */
35+                        tl = xs_list_del(tl, -1);
36+                        more = 1;
37+                    }
38 
39-                *body   = html_timeline(&snac, tl, 0, skip, tl_len, to || tl_len == show, title, page, 0);
40-                *b_size = strlen(*body);
41-                status  = 200;
42+                    xs *page = xs_fmt("/admin?q=%%23%s", q + 1);
43+                    xs *title = xs_fmt(L("Search results for tag %s"), q);
44+
45+                    *body = html_timeline(&snac, tl, 0, skip, show, more, title, page, 0);
46+                    *b_size = strlen(*body);
47+                    status  = 200;
48+                }
49+                else {
50+                    /** search by content **/
51+                    int to = 0;
52+                    int msecs = atoi(xs_dict_get_def(q_vars, "msecs", "0"));
53+                    xs *tl = content_search(&snac, q, 1, skip, show, msecs, &to);
54+                    xs *title = NULL;
55+                    xs *page = xs_fmt("/admin?q=%s&msecs=%d", q, msecs + 10);
56+                    int tl_len = xs_list_len(tl);
57+
58+                    if (tl_len)
59+                        title = xs_fmt(L("Search results for '%s'"), q);
60+                    else
61+                    if (skip)
62+                        title = xs_fmt(L("No more matches for '%s'"), q);
63+                    else
64+                        title = xs_fmt(L("Nothing found for '%s'"), q);
65+
66+                    *body   = html_timeline(&snac, tl, 0, skip, tl_len, to || tl_len == show, title, page, 0);
67+                    *b_size = strlen(*body);
68+                    status  = 200;
69+                }
70             }
71             else {
72                 double t = history_mtime(&snac, "timeline.html_");
+1, -1
1@@ -202,7 +202,7 @@ int server_get_handler(xs_dict *req, const char *q_path,
2             }
3             else {
4                 xs *page = xs_fmt("?t=%s", t);
5-                xs *title = xs_fmt(L("Search results for #%s"), t);
6+                xs *title = xs_fmt(L("Search results for tag #%s"), t);
7                 *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0);
8             }
9         }