commit 86571f3
default
·
2023-08-14 09:24:41 +0000 UTC
parent 64111f8
The instance URL can now show a timeline.
M
html.c
+73,
-0
1@@ -244,8 +244,81 @@ xs_str *html_instance_header(xs_str *s)
2 {
3 s = html_base_header(s);
4
5+ {
6+ FILE *f;
7+ xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir);
8+
9+ if ((f = fopen(g_css_fn, "r")) != NULL) {
10+ xs *css = xs_readall(f);
11+ fclose(f);
12+
13+ xs *s1 = xs_fmt("<style>%s</style>\n", css);
14+ s = xs_str_cat(s, s1);
15+ }
16+ }
17+
18+ const char *host = xs_dict_get(srv_config, "host");
19+ const char *title = xs_dict_get(srv_config, "title");
20+ const char *sdesc = xs_dict_get(srv_config, "short_description");
21+ const char *email = xs_dict_get(srv_config, "admin_email");
22+ const char *acct = xs_dict_get(srv_config, "admin_account");
23+
24+ {
25+ xs *s1 = xs_fmt("<title>%s</title>\n", title && *title ? title : host);
26+ s = xs_str_cat(s, s1);
27+ }
28+
29 s = xs_str_cat(s, "</head>\n<body>\n");
30
31+ s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n");
32+
33+ {
34+ xs *s1 = xs_fmt(
35+ "<p><b>%s</b> is a "
36+ "<a href=\"https:/" "/en.wikipedia.org/wiki/Fediverse\">Fediverse</a> "
37+ "instance that uses the "
38+ "<a href=\"https:/" "/en.wikipedia.org/wiki/ActivityPub\">ActivityPub</a> "
39+ "protocol. In other words, users at this host can communicate with people "
40+ "that use software like Mastodon, Pleroma, Friendica, etc. "
41+ "all around the world.</p>\n"
42+ "<p>This server runs the "
43+ "<a href=\"" WHAT_IS_SNAC_URL "\">snac</a> software and there is no "
44+ "automatic sign-up process.</p>\n",
45+ host);
46+ s = xs_str_cat(s, s1);
47+ }
48+
49+ s = xs_str_cat(s, "<dl>\n");
50+
51+ if (sdesc && *sdesc) {
52+ xs *s1 = xs_fmt("<di><dt>%s</dt><dd>%s</dd></di>\n", L("Site description"), sdesc);
53+ s = xs_str_cat(s, s1);
54+ }
55+ if (email && *email) {
56+ xs *s1 = xs_fmt("<di><dt>%s</dt><dd>"
57+ "<a href=\"mailto:%s\">%s</a></dd></di>\n",
58+ L("Admin email"), email, email);
59+
60+ s = xs_str_cat(s, s1);
61+ }
62+ if (acct && *acct) {
63+ xs *s1 = xs_fmt("<di><dt>%s</dt><dd>"
64+ "<a href=\"%s/%s\">@%s@%s</a></dd></di>\n",
65+ L("Admin account"), srv_baseurl, acct, acct, host);
66+
67+ s = xs_str_cat(s, s1);
68+ }
69+
70+ s = xs_str_cat(s, "</dl>\n");
71+
72+ s = xs_str_cat(s, "</div>\n");
73+
74+ {
75+ xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n",
76+ L("Recent posts by users in this instance"));
77+ s = xs_str_cat(s, s1);
78+ }
79+
80 return s;
81 }
82
M
httpd.c
+8,
-1
1@@ -114,7 +114,14 @@ int server_get_handler(xs_dict *req, const char *q_path,
2
3 /* is it the server root? */
4 if (*q_path == '\0') {
5- if ((*body = greeting_html()) != NULL)
6+ if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) {
7+ xs *tl = timeline_instance_list(0, 30);
8+ *body = html_timeline(NULL, tl, 0, 0, 0, 0);
9+ }
10+ else
11+ *body = greeting_html();
12+
13+ if (*body)
14 status = 200;
15 }
16 else
M
main.c
+0,
-2
1@@ -55,8 +55,6 @@ char *get_argv(int *argi, int argc, char *argv[])
2
3 #define GET_ARGV() get_argv(&argi, argc, argv)
4
5-d_char *html_timeline(snac *snac, char *list, int local);
6-
7 int main(int argc, char *argv[])
8 {
9 char *cmd;
M
snac.h
+2,
-0
1@@ -259,6 +259,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach);
2 xs_str *sanitize(const char *content);
3 xs_str *encode_html(const char *str);
4
5+xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more);
6+
7 int html_get_handler(const xs_dict *req, const char *q_path,
8 char **body, int *b_size, char **ctype, xs_str **etag);
9 int html_post_handler(const xs_dict *req, const char *q_path,
M
utils.c
+3,
-1
1@@ -27,7 +27,9 @@ static const char *default_srv_config = "{"
2 "\"timeline_purge_days\": 120,"
3 "\"local_purge_days\": 0,"
4 "\"admin_email\": \"\","
5- "\"admin_account\": \"\""
6+ "\"admin_account\": \"\","
7+ "\"title\": \"\","
8+ "\"short_description\": \"\""
9 "}";
10
11 static const char *default_css =