commit a5766a6

default  ·  2024-05-09 08:04:45 +0000 UTC
parent 7b0e928
The /admin page now accepts ?q=regex for a content search.
1 files changed,  +33, -20
M html.c
M html.c
+33, -20
 1@@ -2560,35 +2560,48 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2             status = 401;
 3         }
 4         else {
 5-            double t = history_mtime(&snac, "timeline.html_");
 6+            char *q = xs_dict_get(q_vars, "q");
 7 
 8-            /* if enabled by admin, return a cached page if its timestamp is:
 9-               a) newer than the timeline timestamp
10-               b) newer than the start time of the server
11-            */
12-            if (cache && t > timeline_mtime(&snac) && t > p_state->srv_start_time) {
13-                snac_debug(&snac, 1, xs_fmt("serving cached timeline"));
14+            if (q && *q) {
15+                /* search by content */
16+                int to = 0;
17+                xs *tl = content_search(&snac, q, 1, 0, show, &to);
18 
19-                status = history_get(&snac, "timeline.html_", body, b_size,
20-                            xs_dict_get(req, "if-none-match"), etag);
21+                *body   = html_timeline(&snac, tl, 0, 0, show, 0, NULL, "/admin", 1);
22+                *b_size = strlen(*body);
23+                status  = 200;
24             }
25             else {
26-                snac_debug(&snac, 1, xs_fmt("building timeline"));
27+                double t = history_mtime(&snac, "timeline.html_");
28 
29-                xs *list = timeline_list(&snac, "private", skip, show);
30-                xs *next = timeline_list(&snac, "private", skip + show, 1);
31+                /* if enabled by admin, return a cached page if its timestamp is:
32+                   a) newer than the timeline timestamp
33+                   b) newer than the start time of the server
34+                */
35+                if (cache && t > timeline_mtime(&snac) && t > p_state->srv_start_time) {
36+                    snac_debug(&snac, 1, xs_fmt("serving cached timeline"));
37 
38-                xs *pins = pinned_list(&snac);
39-                pins = xs_list_cat(pins, list);
40+                    status = history_get(&snac, "timeline.html_", body, b_size,
41+                                xs_dict_get(req, "if-none-match"), etag);
42+                }
43+                else {
44+                    snac_debug(&snac, 1, xs_fmt("building timeline"));
45 
46-                *body = html_timeline(&snac, pins, 0, skip, show,
47-                        xs_list_len(next), NULL, "/admin", 1);
48+                    xs *list = timeline_list(&snac, "private", skip, show);
49+                    xs *next = timeline_list(&snac, "private", skip + show, 1);
50 
51-                *b_size = strlen(*body);
52-                status  = 200;
53+                    xs *pins = pinned_list(&snac);
54+                    pins = xs_list_cat(pins, list);
55+
56+                    *body = html_timeline(&snac, pins, 0, skip, show,
57+                            xs_list_len(next), NULL, "/admin", 1);
58 
59-                if (save)
60-                    history_add(&snac, "timeline.html_", *body, *b_size, etag);
61+                    *b_size = strlen(*body);
62+                    status  = 200;
63+
64+                    if (save)
65+                        history_add(&snac, "timeline.html_", *body, *b_size, etag);
66+                }
67             }
68         }
69     }