Fix missing spaces in title on /statuses/

https://cultofshiv.wtf/@SleepyCatten/110871145730991389
This commit is contained in:
blankie 2023-12-06 16:59:40 +11:00
parent 1f5e329385
commit 0d97483017
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
1 changed files with 12 additions and 5 deletions

View File

@ -58,19 +58,26 @@ void status_route(const httplib::Request& req, httplib::Response& res) {
static inline std::string make_title(const Post& post) { static inline std::string make_title(const Post& post) {
LXB::HTML::Document document(post.content.str); LXB::HTML::Document document(post.content.str);
size_t content_len; std::string content = get_text_content(document.body());
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() + "): "; std::string title = post.account.display_name + " (@" + post.account.acct() + "): ";
if (content_len) { if (!content.empty()) {
title.append(content, content_len > 50 ? 50 : content_len); if (content.size() > 50) {
if (content_len > 50) { title.append(content, 0, 50);
title += ""; title += "";
} else {
title += std::move(content);
} }
} else { } else {
title += "Post"; title += "Post";
} }
for (size_t i = 0; i < title.size(); i++) {
if (title[i] == '\n') {
title[i] = ' ';
}
}
return title; return title;
} }