From 0d974830175bab0197e31641fa1ef4f6390d9d33 Mon Sep 17 00:00:00 2001 From: blankie Date: Wed, 6 Dec 2023 16:59:40 +1100 Subject: [PATCH] Fix missing spaces in title on /statuses/ https://cultofshiv.wtf/@SleepyCatten/110871145730991389 --- routes/status.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/routes/status.cpp b/routes/status.cpp index 7bae3ef..e6e6474 100644 --- a/routes/status.cpp +++ b/routes/status.cpp @@ -58,19 +58,26 @@ void status_route(const httplib::Request& req, httplib::Response& res) { 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(lxb_dom_node_text_content(document.body(), &content_len)); + std::string content = get_text_content(document.body()); 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) { + if (!content.empty()) { + if (content.size() > 50) { + title.append(content, 0, 50); title += "…"; + } else { + title += std::move(content); } } else { title += "Post"; } + for (size_t i = 0; i < title.size(); i++) { + if (title[i] == '\n') { + title[i] = ' '; + } + } + return title; }