From 8cb8e86de667da5b082af42b70939c58fc71a80a Mon Sep 17 00:00:00 2001 From: blankie Date: Thu, 23 Nov 2023 19:58:44 +1100 Subject: [PATCH] Add content warning support --- routes/css.cpp | 2 +- servehelper.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/routes/css.cpp b/routes/css.cpp index 3638df6..4ae4a70 100644 --- a/routes/css.cpp +++ b/routes/css.cpp @@ -29,7 +29,7 @@ html { font-family: sans-serif; padding: 10px; } -p { +p, details { margin-top: 1em; margin-bottom: 1em; } diff --git a/servehelper.cpp b/servehelper.cpp index e92d956..b33fec2 100644 --- a/servehelper.cpp +++ b/servehelper.cpp @@ -176,6 +176,15 @@ Element serialize_post(const httplib::Request& req, const std::string& server, c : "Created: "s + full_time(post.created_at) + "\nEdited: " + full_time(post.edited_at); const char* time_badge = post.edited_at < 0 ? "" : " (edited)"; + Node contents = preprocess_html(req, server, post.emojis, post.content); + if (post.sensitive) { + std::string spoiler_text = !post.spoiler_text.empty() ? post.spoiler_text : "See more"; + contents = Element("details", { + Element("summary", {preprocess_html(req, post.emojis, std::move(spoiler_text))}), + std::move(contents), + }); + } + Element div("div", {{"class", "post"}}, { Element("div", {{"class", "post-header"}}, { Element("a", {{"href", get_origin(req) + '/' + server + "/@" + post.account.acct(false)}}, { @@ -190,7 +199,7 @@ Element serialize_post(const httplib::Request& req, const std::string& server, c }), }), - preprocess_html(req, server, post.emojis, post.content), + contents, }); return div; }