From 86571f37bb3e85acaed6d0212b5543130a6766ce Mon Sep 17 00:00:00 2001 From: default Date: Mon, 14 Aug 2023 11:24:41 +0200 Subject: The instance URL can now show a timeline. --- html.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ httpd.c | 9 +++++++- main.c | 2 -- snac.h | 2 ++ utils.c | 4 +++- 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) { s = html_base_header(s); + { + FILE *f; + xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir); + + if ((f = fopen(g_css_fn, "r")) != NULL) { + xs *css = xs_readall(f); + fclose(f); + + xs *s1 = xs_fmt("\n", css); + s = xs_str_cat(s, s1); + } + } + + const char *host = xs_dict_get(srv_config, "host"); + const char *title = xs_dict_get(srv_config, "title"); + const char *sdesc = xs_dict_get(srv_config, "short_description"); + const char *email = xs_dict_get(srv_config, "admin_email"); + const char *acct = xs_dict_get(srv_config, "admin_account"); + + { + xs *s1 = xs_fmt("%s\n", title && *title ? title : host); + s = xs_str_cat(s, s1); + } + s = xs_str_cat(s, "\n\n"); + s = xs_str_cat(s, "
\n"); + + { + xs *s1 = xs_fmt( + "

%s is a " + "Fediverse " + "instance that uses the " + "ActivityPub " + "protocol. In other words, users at this host can communicate with people " + "that use software like Mastodon, Pleroma, Friendica, etc. " + "all around the world.

\n" + "

This server runs the " + "snac software and there is no " + "automatic sign-up process.

\n", + host); + s = xs_str_cat(s, s1); + } + + s = xs_str_cat(s, "
\n"); + + if (sdesc && *sdesc) { + xs *s1 = xs_fmt("
%s
%s
\n", L("Site description"), sdesc); + s = xs_str_cat(s, s1); + } + if (email && *email) { + xs *s1 = xs_fmt("
%s
" + "%s
\n", + L("Admin email"), email, email); + + s = xs_str_cat(s, s1); + } + if (acct && *acct) { + xs *s1 = xs_fmt("
%s
" + "@%s@%s
\n", + L("Admin account"), srv_baseurl, acct, acct, host); + + s = xs_str_cat(s, s1); + } + + s = xs_str_cat(s, "
\n"); + + s = xs_str_cat(s, "
\n"); + + { + xs *s1 = xs_fmt("

%s

\n", + L("Recent posts by users in this instance")); + s = xs_str_cat(s, s1); + } + return s; } 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, /* is it the server root? */ if (*q_path == '\0') { - if ((*body = greeting_html()) != NULL) + if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { + xs *tl = timeline_instance_list(0, 30); + *body = html_timeline(NULL, tl, 0, 0, 0, 0); + } + else + *body = greeting_html(); + + if (*body) status = 200; } 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[]) #define GET_ARGV() get_argv(&argi, argc, argv) -d_char *html_timeline(snac *snac, char *list, int local); - int main(int argc, char *argv[]) { 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); xs_str *sanitize(const char *content); xs_str *encode_html(const char *str); +xs_str *html_timeline(snac *user, const xs_list *list, int local, int skip, int show, int show_more); + int html_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype, xs_str **etag); int 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 = "{" "\"timeline_purge_days\": 120," "\"local_purge_days\": 0," "\"admin_email\": \"\"," - "\"admin_account\": \"\"" + "\"admin_account\": \"\"," + "\"title\": \"\"," + "\"short_description\": \"\"" "}"; static const char *default_css = -- cgit v1.2.3