summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-08-14 11:24:41 +0200
committerGravatar default2023-08-14 11:24:41 +0200
commit86571f37bb3e85acaed6d0212b5543130a6766ce (patch)
tree1b2209d18369e527da3bed75cdb09927476283ad
parentSome work towards an instance timeline. (diff)
downloadsnac2-86571f37bb3e85acaed6d0212b5543130a6766ce.tar.gz
snac2-86571f37bb3e85acaed6d0212b5543130a6766ce.tar.xz
snac2-86571f37bb3e85acaed6d0212b5543130a6766ce.zip
The instance URL can now show a timeline.
-rw-r--r--html.c73
-rw-r--r--httpd.c9
-rw-r--r--main.c2
-rw-r--r--snac.h2
-rw-r--r--utils.c4
5 files changed, 86 insertions, 4 deletions
diff --git a/html.c b/html.c
index b941464..1da0b9c 100644
--- a/html.c
+++ b/html.c
@@ -244,8 +244,81 @@ xs_str *html_instance_header(xs_str *s)
244{ 244{
245 s = html_base_header(s); 245 s = html_base_header(s);
246 246
247 {
248 FILE *f;
249 xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir);
250
251 if ((f = fopen(g_css_fn, "r")) != NULL) {
252 xs *css = xs_readall(f);
253 fclose(f);
254
255 xs *s1 = xs_fmt("<style>%s</style>\n", css);
256 s = xs_str_cat(s, s1);
257 }
258 }
259
260 const char *host = xs_dict_get(srv_config, "host");
261 const char *title = xs_dict_get(srv_config, "title");
262 const char *sdesc = xs_dict_get(srv_config, "short_description");
263 const char *email = xs_dict_get(srv_config, "admin_email");
264 const char *acct = xs_dict_get(srv_config, "admin_account");
265
266 {
267 xs *s1 = xs_fmt("<title>%s</title>\n", title && *title ? title : host);
268 s = xs_str_cat(s, s1);
269 }
270
247 s = xs_str_cat(s, "</head>\n<body>\n"); 271 s = xs_str_cat(s, "</head>\n<body>\n");
248 272
273 s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n");
274
275 {
276 xs *s1 = xs_fmt(
277 "<p><b>%s</b> is a "
278 "<a href=\"https:/" "/en.wikipedia.org/wiki/Fediverse\">Fediverse</a> "
279 "instance that uses the "
280 "<a href=\"https:/" "/en.wikipedia.org/wiki/ActivityPub\">ActivityPub</a> "
281 "protocol. In other words, users at this host can communicate with people "
282 "that use software like Mastodon, Pleroma, Friendica, etc. "
283 "all around the world.</p>\n"
284 "<p>This server runs the "
285 "<a href=\"" WHAT_IS_SNAC_URL "\">snac</a> software and there is no "
286 "automatic sign-up process.</p>\n",
287 host);
288 s = xs_str_cat(s, s1);
289 }
290
291 s = xs_str_cat(s, "<dl>\n");
292
293 if (sdesc && *sdesc) {
294 xs *s1 = xs_fmt("<di><dt>%s</dt><dd>%s</dd></di>\n", L("Site description"), sdesc);
295 s = xs_str_cat(s, s1);
296 }
297 if (email && *email) {
298 xs *s1 = xs_fmt("<di><dt>%s</dt><dd>"
299 "<a href=\"mailto:%s\">%s</a></dd></di>\n",
300 L("Admin email"), email, email);
301
302 s = xs_str_cat(s, s1);
303 }
304 if (acct && *acct) {
305 xs *s1 = xs_fmt("<di><dt>%s</dt><dd>"
306 "<a href=\"%s/%s\">@%s@%s</a></dd></di>\n",
307 L("Admin account"), srv_baseurl, acct, acct, host);
308
309 s = xs_str_cat(s, s1);
310 }
311
312 s = xs_str_cat(s, "</dl>\n");
313
314 s = xs_str_cat(s, "</div>\n");
315
316 {
317 xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n",
318 L("Recent posts by users in this instance"));
319 s = xs_str_cat(s, s1);
320 }
321
249 return s; 322 return s;
250} 323}
251 324
diff --git a/httpd.c b/httpd.c
index 85f098c..cdead11 100644
--- a/httpd.c
+++ b/httpd.c
@@ -114,7 +114,14 @@ int server_get_handler(xs_dict *req, const char *q_path,
114 114
115 /* is it the server root? */ 115 /* is it the server root? */
116 if (*q_path == '\0') { 116 if (*q_path == '\0') {
117 if ((*body = greeting_html()) != NULL) 117 if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) {
118 xs *tl = timeline_instance_list(0, 30);
119 *body = html_timeline(NULL, tl, 0, 0, 0, 0);
120 }
121 else
122 *body = greeting_html();
123
124 if (*body)
118 status = 200; 125 status = 200;
119 } 126 }
120 else 127 else
diff --git a/main.c b/main.c
index 8030673..bce8198 100644
--- a/main.c
+++ b/main.c
@@ -55,8 +55,6 @@ char *get_argv(int *argi, int argc, char *argv[])
55 55
56#define GET_ARGV() get_argv(&argi, argc, argv) 56#define GET_ARGV() get_argv(&argi, argc, argv)
57 57
58d_char *html_timeline(snac *snac, char *list, int local);
59
60int main(int argc, char *argv[]) 58int main(int argc, char *argv[])
61{ 59{
62 char *cmd; 60 char *cmd;
diff --git a/snac.h b/snac.h
index 1365816..155205b 100644
--- a/snac.h
+++ b/snac.h
@@ -259,6 +259,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach);
259xs_str *sanitize(const char *content); 259xs_str *sanitize(const char *content);
260xs_str *encode_html(const char *str); 260xs_str *encode_html(const char *str);
261 261
262xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more);
263
262int html_get_handler(const xs_dict *req, const char *q_path, 264int html_get_handler(const xs_dict *req, const char *q_path,
263 char **body, int *b_size, char **ctype, xs_str **etag); 265 char **body, int *b_size, char **ctype, xs_str **etag);
264int html_post_handler(const xs_dict *req, const char *q_path, 266int html_post_handler(const xs_dict *req, const char *q_path,
diff --git a/utils.c b/utils.c
index 1e46613..e9d1447 100644
--- a/utils.c
+++ b/utils.c
@@ -27,7 +27,9 @@ static const char *default_srv_config = "{"
27 "\"timeline_purge_days\": 120," 27 "\"timeline_purge_days\": 120,"
28 "\"local_purge_days\": 0," 28 "\"local_purge_days\": 0,"
29 "\"admin_email\": \"\"," 29 "\"admin_email\": \"\","
30 "\"admin_account\": \"\"" 30 "\"admin_account\": \"\","
31 "\"title\": \"\","
32 "\"short_description\": \"\""
31 "}"; 33 "}";
32 34
33static const char *default_css = 35static const char *default_css =