diff options
| author | 2022-09-28 15:41:07 +0200 | |
|---|---|---|
| committer | 2022-09-28 15:41:07 +0200 | |
| commit | 233d7d8a10bbef5200b5026bb59acfe5d8a252fd (patch) | |
| tree | 39ec3e7360496de4ad759ccbdd322dc76ebf754c /html.c | |
| parent | More HTML work. (diff) | |
| download | snac2-233d7d8a10bbef5200b5026bb59acfe5d8a252fd.tar.gz snac2-233d7d8a10bbef5200b5026bb59acfe5d8a252fd.tar.xz snac2-233d7d8a10bbef5200b5026bb59acfe5d8a252fd.zip | |
More HTML work.
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 93 |
1 files changed, 92 insertions, 1 deletions
| @@ -372,12 +372,84 @@ d_char *html_top_controls(snac *snac, d_char *s) | |||
| 372 | 372 | ||
| 373 | d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level) | 373 | d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level) |
| 374 | { | 374 | { |
| 375 | char *id = xs_dict_get(msg, "id"); | 375 | char *id = xs_dict_get(msg, "id"); |
| 376 | char *type = xs_dict_get(msg, "type"); | ||
| 377 | char *meta = xs_dict_get(msg, "_snac"); | ||
| 378 | xs *actor_o = NULL; | ||
| 379 | char *actor; | ||
| 376 | 380 | ||
| 377 | /* return if already seen */ | 381 | /* return if already seen */ |
| 378 | if (xs_set_add(seen, id) == 0) | 382 | if (xs_set_add(seen, id) == 0) |
| 379 | return s; | 383 | return s; |
| 380 | 384 | ||
| 385 | if (strcmp(type, "Follow") == 0) | ||
| 386 | return s; | ||
| 387 | |||
| 388 | /* bring the main actor */ | ||
| 389 | if ((actor = xs_dict_get(msg, "attributedTo")) == NULL) | ||
| 390 | return s; | ||
| 391 | |||
| 392 | if (!valid_status(actor_get(snac, actor, &actor_o))) | ||
| 393 | return s; | ||
| 394 | |||
| 395 | if (level == 0) { | ||
| 396 | char *referrer; | ||
| 397 | |||
| 398 | s = xs_str_cat(s, "<div class=\"snac-post\">\n"); | ||
| 399 | |||
| 400 | /* print the origin of the post, if any */ | ||
| 401 | if ((referrer = xs_dict_get(meta, "referrer")) != NULL) { | ||
| 402 | xs *actor_r = NULL; | ||
| 403 | |||
| 404 | if (valid_status(actor_get(snac, referrer, &actor_r))) { | ||
| 405 | char *name; | ||
| 406 | |||
| 407 | if ((name = xs_dict_get(actor_r, "name")) == NULL) | ||
| 408 | name = xs_dict_get(actor_r, "preferredUsername"); | ||
| 409 | |||
| 410 | xs *s1 = xs_fmt( | ||
| 411 | "<div class=\"snac-origin\">\n" | ||
| 412 | "<a href=\"%s\">%s</a> %s</div>", | ||
| 413 | xs_dict_get(actor_r, "id"), | ||
| 414 | name, | ||
| 415 | "boosted" | ||
| 416 | ); | ||
| 417 | |||
| 418 | s = xs_str_cat(s, s1); | ||
| 419 | } | ||
| 420 | } | ||
| 421 | } | ||
| 422 | else | ||
| 423 | s = xs_str_cat(s, "<div class=\"snac-child\">\n"); | ||
| 424 | |||
| 425 | s = html_msg_icon(snac, s, msg); | ||
| 426 | |||
| 427 | /* add the content */ | ||
| 428 | { | ||
| 429 | xs *c = xs_dup(xs_dict_get(msg, "content")); | ||
| 430 | |||
| 431 | /* do some tweaks to the content */ | ||
| 432 | c = xs_replace_i(c, "\r", ""); | ||
| 433 | |||
| 434 | while (xs_endswith(c, "<br><br>")) | ||
| 435 | c = xs_crop(c, 0, -4); | ||
| 436 | |||
| 437 | c = xs_replace_i(c, "<br><br>", "<p>"); | ||
| 438 | |||
| 439 | if (!xs_startswith(c, "<p>")) { | ||
| 440 | xs *s1 = c; | ||
| 441 | c = xs_fmt("<p>%s</p>", s1); | ||
| 442 | } | ||
| 443 | |||
| 444 | xs *s1 = xs_fmt("<div class=\"e-content snac-content\">\n%s", c); | ||
| 445 | |||
| 446 | s = xs_str_cat(s, s1); | ||
| 447 | |||
| 448 | s = xs_str_cat(s, "</div>\n"); | ||
| 449 | } | ||
| 450 | |||
| 451 | s = xs_str_cat(s, "</div>\n"); | ||
| 452 | |||
| 381 | return s; | 453 | return s; |
| 382 | } | 454 | } |
| 383 | 455 | ||
| @@ -394,12 +466,16 @@ d_char *html_timeline(snac *snac, char *list, int local) | |||
| 394 | if (!local) | 466 | if (!local) |
| 395 | s = html_top_controls(snac, s); | 467 | s = html_top_controls(snac, s); |
| 396 | 468 | ||
| 469 | s = xs_str_cat(s, "<div class=\"snac-posts\">\n"); | ||
| 470 | |||
| 397 | while (xs_list_iter(&list, &v)) { | 471 | while (xs_list_iter(&list, &v)) { |
| 398 | xs *msg = timeline_get(snac, v); | 472 | xs *msg = timeline_get(snac, v); |
| 399 | 473 | ||
| 400 | s = html_entry(snac, s, msg, seen, 0); | 474 | s = html_entry(snac, s, msg, seen, 0); |
| 401 | } | 475 | } |
| 402 | 476 | ||
| 477 | s = xs_str_cat(s, "</div>\n"); | ||
| 478 | |||
| 403 | #if 0 | 479 | #if 0 |
| 404 | s = xs_str_cat(s, "<h1>HI</h1>\n"); | 480 | s = xs_str_cat(s, "<h1>HI</h1>\n"); |
| 405 | 481 | ||
| @@ -415,6 +491,21 @@ d_char *html_timeline(snac *snac, char *list, int local) | |||
| 415 | s = xs_str_cat(s, "</html>\n"); | 491 | s = xs_str_cat(s, "</html>\n"); |
| 416 | #endif | 492 | #endif |
| 417 | 493 | ||
| 494 | { | ||
| 495 | /* footer */ | ||
| 496 | xs *s1 = xs_fmt( | ||
| 497 | "<div class=\"snac-footer\">\n" | ||
| 498 | "<a href=\"%s\">%s</a> - " | ||
| 499 | "powered by <abbr title=\"Social Networks Are Crap\">snac</abbr></div>\n", | ||
| 500 | srv_baseurl, | ||
| 501 | L("about this site") | ||
| 502 | ); | ||
| 503 | |||
| 504 | s = xs_str_cat(s, s1); | ||
| 505 | } | ||
| 506 | |||
| 507 | s = xs_str_cat(s, "</body>\n</html>\n"); | ||
| 508 | |||
| 418 | xs_set_free(seen); | 509 | xs_set_free(seen); |
| 419 | 510 | ||
| 420 | return s; | 511 | return s; |