mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-10 03:50:38 +03:00
More HTML work.
This commit is contained in:
parent
69bc24a4bf
commit
233d7d8a10
1
data.c
1
data.c
@ -606,6 +606,7 @@ void timeline_admire(snac *snac, char *id, char *admirer, int like)
|
|||||||
list = xs_list_append(list, admirer);
|
list = xs_list_append(list, admirer);
|
||||||
|
|
||||||
/* set the admirer as the referrer */
|
/* set the admirer as the referrer */
|
||||||
|
if (!like)
|
||||||
meta = xs_dict_set(meta, "referrer", admirer);
|
meta = xs_dict_set(meta, "referrer", admirer);
|
||||||
|
|
||||||
/* re-store */
|
/* re-store */
|
||||||
|
91
html.c
91
html.c
@ -373,11 +373,83 @@ d_char *html_top_controls(snac *snac, d_char *s)
|
|||||||
d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level)
|
d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level)
|
||||||
{
|
{
|
||||||
char *id = xs_dict_get(msg, "id");
|
char *id = xs_dict_get(msg, "id");
|
||||||
|
char *type = xs_dict_get(msg, "type");
|
||||||
|
char *meta = xs_dict_get(msg, "_snac");
|
||||||
|
xs *actor_o = NULL;
|
||||||
|
char *actor;
|
||||||
|
|
||||||
/* return if already seen */
|
/* return if already seen */
|
||||||
if (xs_set_add(seen, id) == 0)
|
if (xs_set_add(seen, id) == 0)
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
if (strcmp(type, "Follow") == 0)
|
||||||
|
return s;
|
||||||
|
|
||||||
|
/* bring the main actor */
|
||||||
|
if ((actor = xs_dict_get(msg, "attributedTo")) == NULL)
|
||||||
|
return s;
|
||||||
|
|
||||||
|
if (!valid_status(actor_get(snac, actor, &actor_o)))
|
||||||
|
return s;
|
||||||
|
|
||||||
|
if (level == 0) {
|
||||||
|
char *referrer;
|
||||||
|
|
||||||
|
s = xs_str_cat(s, "<div class=\"snac-post\">\n");
|
||||||
|
|
||||||
|
/* print the origin of the post, if any */
|
||||||
|
if ((referrer = xs_dict_get(meta, "referrer")) != NULL) {
|
||||||
|
xs *actor_r = NULL;
|
||||||
|
|
||||||
|
if (valid_status(actor_get(snac, referrer, &actor_r))) {
|
||||||
|
char *name;
|
||||||
|
|
||||||
|
if ((name = xs_dict_get(actor_r, "name")) == NULL)
|
||||||
|
name = xs_dict_get(actor_r, "preferredUsername");
|
||||||
|
|
||||||
|
xs *s1 = xs_fmt(
|
||||||
|
"<div class=\"snac-origin\">\n"
|
||||||
|
"<a href=\"%s\">%s</a> %s</div>",
|
||||||
|
xs_dict_get(actor_r, "id"),
|
||||||
|
name,
|
||||||
|
"boosted"
|
||||||
|
);
|
||||||
|
|
||||||
|
s = xs_str_cat(s, s1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
s = xs_str_cat(s, "<div class=\"snac-child\">\n");
|
||||||
|
|
||||||
|
s = html_msg_icon(snac, s, msg);
|
||||||
|
|
||||||
|
/* add the content */
|
||||||
|
{
|
||||||
|
xs *c = xs_dup(xs_dict_get(msg, "content"));
|
||||||
|
|
||||||
|
/* do some tweaks to the content */
|
||||||
|
c = xs_replace_i(c, "\r", "");
|
||||||
|
|
||||||
|
while (xs_endswith(c, "<br><br>"))
|
||||||
|
c = xs_crop(c, 0, -4);
|
||||||
|
|
||||||
|
c = xs_replace_i(c, "<br><br>", "<p>");
|
||||||
|
|
||||||
|
if (!xs_startswith(c, "<p>")) {
|
||||||
|
xs *s1 = c;
|
||||||
|
c = xs_fmt("<p>%s</p>", s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
xs *s1 = xs_fmt("<div class=\"e-content snac-content\">\n%s", c);
|
||||||
|
|
||||||
|
s = xs_str_cat(s, s1);
|
||||||
|
|
||||||
|
s = xs_str_cat(s, "</div>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
s = xs_str_cat(s, "</div>\n");
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,12 +466,16 @@ d_char *html_timeline(snac *snac, char *list, int local)
|
|||||||
if (!local)
|
if (!local)
|
||||||
s = html_top_controls(snac, s);
|
s = html_top_controls(snac, s);
|
||||||
|
|
||||||
|
s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
|
||||||
|
|
||||||
while (xs_list_iter(&list, &v)) {
|
while (xs_list_iter(&list, &v)) {
|
||||||
xs *msg = timeline_get(snac, v);
|
xs *msg = timeline_get(snac, v);
|
||||||
|
|
||||||
s = html_entry(snac, s, msg, seen, 0);
|
s = html_entry(snac, s, msg, seen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s = xs_str_cat(s, "</div>\n");
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
s = xs_str_cat(s, "<h1>HI</h1>\n");
|
s = xs_str_cat(s, "<h1>HI</h1>\n");
|
||||||
|
|
||||||
@ -415,6 +491,21 @@ d_char *html_timeline(snac *snac, char *list, int local)
|
|||||||
s = xs_str_cat(s, "</html>\n");
|
s = xs_str_cat(s, "</html>\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
{
|
||||||
|
/* footer */
|
||||||
|
xs *s1 = xs_fmt(
|
||||||
|
"<div class=\"snac-footer\">\n"
|
||||||
|
"<a href=\"%s\">%s</a> - "
|
||||||
|
"powered by <abbr title=\"Social Networks Are Crap\">snac</abbr></div>\n",
|
||||||
|
srv_baseurl,
|
||||||
|
L("about this site")
|
||||||
|
);
|
||||||
|
|
||||||
|
s = xs_str_cat(s, s1);
|
||||||
|
}
|
||||||
|
|
||||||
|
s = xs_str_cat(s, "</body>\n</html>\n");
|
||||||
|
|
||||||
xs_set_free(seen);
|
xs_set_free(seen);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
|
Loading…
Reference in New Issue
Block a user