The instance URL can now show a timeline.

This commit is contained in:
default 2023-08-14 11:24:41 +02:00
parent 64111f85bd
commit 86571f37bb
5 changed files with 86 additions and 4 deletions

73
html.c
View file

@ -244,8 +244,81 @@ xs_str *html_instance_header(xs_str *s)
{ {
s = html_base_header(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, "</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; return s;
} }

View file

@ -114,7 +114,14 @@ int server_get_handler(xs_dict *req, const char *q_path,
/* is it the server root? */ /* is it the server root? */
if (*q_path == '\0') { 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; status = 200;
} }
else else

2
main.c
View file

@ -55,8 +55,6 @@ char *get_argv(int *argi, int argc, char *argv[])
#define GET_ARGV() get_argv(&argi, argc, 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[]) int main(int argc, char *argv[])
{ {
char *cmd; char *cmd;

2
snac.h
View file

@ -259,6 +259,8 @@ xs_str *not_really_markdown(const char *content, xs_list **attach);
xs_str *sanitize(const char *content); xs_str *sanitize(const char *content);
xs_str *encode_html(const char *str); 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, int html_get_handler(const xs_dict *req, const char *q_path,
char **body, int *b_size, char **ctype, xs_str **etag); char **body, int *b_size, char **ctype, xs_str **etag);
int html_post_handler(const xs_dict *req, const char *q_path, int html_post_handler(const xs_dict *req, const char *q_path,

View file

@ -27,7 +27,9 @@ static const char *default_srv_config = "{"
"\"timeline_purge_days\": 120," "\"timeline_purge_days\": 120,"
"\"local_purge_days\": 0," "\"local_purge_days\": 0,"
"\"admin_email\": \"\"," "\"admin_email\": \"\","
"\"admin_account\": \"\"" "\"admin_account\": \"\","
"\"title\": \"\","
"\"short_description\": \"\""
"}"; "}";
static const char *default_css = static const char *default_css =