summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-08-14 11:24:41 +0200
committerdefault <nobody@localhost>2023-08-14 11:24:41 +0200
commit86571f37bb3e85acaed6d0212b5543130a6766ce (patch)
tree1b2209d18369e527da3bed75cdb09927476283ad
parent64111f85bdf1dd74bb3bf1ff6886f497cc74f6bd (diff)
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)
{
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("<style>%s</style>\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("<title>%s</title>\n", title && *title ? title : host);
+ s = xs_str_cat(s, s1);
+ }
+
s = xs_str_cat(s, "</head>\n<body>\n");
+ s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n");
+
+ {
+ xs *s1 = xs_fmt(
+ "<p><b>%s</b> is a "
+ "<a href=\"https:/" "/en.wikipedia.org/wiki/Fediverse\">Fediverse</a> "
+ "instance that uses the "
+ "<a href=\"https:/" "/en.wikipedia.org/wiki/ActivityPub\">ActivityPub</a> "
+ "protocol. In other words, users at this host can communicate with people "
+ "that use software like Mastodon, Pleroma, Friendica, etc. "
+ "all around the world.</p>\n"
+ "<p>This server runs the "
+ "<a href=\"" WHAT_IS_SNAC_URL "\">snac</a> software and there is no "
+ "automatic sign-up process.</p>\n",
+ host);
+ s = xs_str_cat(s, s1);
+ }
+
+ s = xs_str_cat(s, "<dl>\n");
+
+ if (sdesc && *sdesc) {
+ xs *s1 = xs_fmt("<di><dt>%s</dt><dd>%s</dd></di>\n", L("Site description"), sdesc);
+ s = xs_str_cat(s, s1);
+ }
+ if (email && *email) {
+ xs *s1 = xs_fmt("<di><dt>%s</dt><dd>"
+ "<a href=\"mailto:%s\">%s</a></dd></di>\n",
+ L("Admin email"), email, email);
+
+ s = xs_str_cat(s, s1);
+ }
+ if (acct && *acct) {
+ xs *s1 = xs_fmt("<di><dt>%s</dt><dd>"
+ "<a href=\"%s/%s\">@%s@%s</a></dd></di>\n",
+ L("Admin account"), srv_baseurl, acct, acct, host);
+
+ s = xs_str_cat(s, s1);
+ }
+
+ s = xs_str_cat(s, "</dl>\n");
+
+ s = xs_str_cat(s, "</div>\n");
+
+ {
+ xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\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 =