diff --git a/routes/status.cpp b/routes/status.cpp index dd898b1..3bd70c3 100644 --- a/routes/status.cpp +++ b/routes/status.cpp @@ -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(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; }