Add title to status pages

This commit is contained in:
blankie 2023-11-24 12:09:49 +11:00
parent c92b063581
commit c5b2d5dcf1
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 24 additions and 1 deletions

View File

@ -1,8 +1,12 @@
#include "routes.h"
#include "../lxb_wrapper.h"
#include "../servehelper.h"
#include "../client.h"
#include "../models.h"
static inline std::string make_title(const Post& post);
void status_route(const httplib::Request& req, httplib::Response& res) {
std::string server = req.matches.str(1);
std::string id = req.matches.str(2);
@ -44,5 +48,24 @@ void status_route(const httplib::Request& req, httplib::Response& res) {
body.nodes.push_back(serialize_post(req, server, i));
}
serve(req, res, "", std::move(body));
serve(req, res, make_title(*post), std::move(body));
}
static inline std::string make_title(const Post& post) {
LXB::HTML::Document document(post.content.str);
size_t content_len;
const char* content = reinterpret_cast<const char*>(lxb_dom_node_text_content(document.body(), &content_len));
std::string title = post.account.display_name + " (" + post.account.acct() + "): ";
if (content_len) {
title.append(content, content_len > 50 ? 50 : content_len);
if (content_len > 50) {
title += "";
}
} else {
title += "Post";
}
return title;
}