From d37f886f62f9fde7d51cfe259825796fa5ad88b1 Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Tue, 17 Dec 2024 20:34:28 -0500 Subject: [PATCH] domain --- src/apps/web/WebData.h | 34 +++++++++++++++++++++++++++---- src/apps/web/WebReader.cpp | 15 ++++++++++++++ src/apps/web/static/oddbean.css | 5 +++++ src/apps/web/tmpls/feed/item.tmpl | 5 ++++- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/apps/web/WebData.h b/src/apps/web/WebData.h index 7ac3ed7..ce9c131 100644 --- a/src/apps/web/WebData.h +++ b/src/apps/web/WebData.h @@ -237,11 +237,32 @@ struct Event { return encodeBech32Simple("note", root); } + struct Summary { + std::string text; + std::string url; + + std::string getDomain() { + static RE2 matcher(R"((?i)https?://(?:[\w-]+[.])*([\w-]+[.]\w+))"); + + std::string_view contentSv(url); + re2::StringPiece input(contentSv); + re2::StringPiece match; + + if (RE2::Consume(&input, matcher, &match)) { + return std::string(match); + } + + return ""; + }; + }; + // FIXME: Use "subject" tag if present? // FIXME: Don't truncate UTF-8 mid-sequence // FIXME: Don't put ellipsis if truncated text ends in punctuation - std::string summaryHtml(bool withLink = true) const { + Summary summaryHtml() const { + Summary output; + std::string content = json.at("content").get_string(); auto firstUrl = stripUrls(content); @@ -252,6 +273,10 @@ struct Event { textAbbrev(content, 100); templarInternal::htmlEscape(content, true); + output.text = std::move(content); + output.url = std::move(firstUrl); + +/* if (withLink && firstUrl.size()) { while (content.size() && isspace(content.back())) content.pop_back(); if (content.empty()) { @@ -262,8 +287,9 @@ struct Event { return std::string("" + content + ""; } + */ - return content; + return output; } @@ -520,7 +546,7 @@ struct EventThread { if (p == eventCache.end()) return ""; const auto &elem = p->second; - return elem.summaryHtml(false); + return elem.summaryHtml().text; } @@ -547,7 +573,7 @@ struct EventThread { ctx.abbrev = focusOnPubkey && *focusOnPubkey != pubkey; if (ctx.abbrev) { - ctx.content = elem.summaryHtml(); + ctx.content = elem.summaryHtml().text; } else { ctx.content = templarInternal::htmlEscape(elem.json.at("content").get_string(), false); preprocessEventContent(txn, decomp, elem, userCache, ctx.content); diff --git a/src/apps/web/WebReader.cpp b/src/apps/web/WebReader.cpp index 298a215..2eafa24 100644 --- a/src/apps/web/WebReader.cpp +++ b/src/apps/web/WebReader.cpp @@ -104,15 +104,30 @@ TemplarResult renderFeed(lmdb::txn &txn, Decompressor &decomp, UserCache &userCa auto ev = Event::fromLevId(txn, fe.levId); ev.populateJson(txn, decomp); + auto summary = ev.summaryHtml(); + std::string url; + if (summary.url.size()) { + url = summary.url; + } else { + url += "/e/"; + url += ev.getNoteId(); + } + struct { uint64_t n; const Event &ev; + const std::string &text; + const std::string &url; + const std::string &domain; const User &user; std::string timestamp; FeedReader::EventInfo &info; } ctx = { offset + n, ev, + summary.text, + url, + summary.getDomain(), *userCache.getUser(txn, decomp, ev.getPubkey()), renderTimestamp(now, ev.getCreatedAt()), fe.info, diff --git a/src/apps/web/static/oddbean.css b/src/apps/web/static/oddbean.css index 39d6ad2..4ff00f9 100644 --- a/src/apps/web/static/oddbean.css +++ b/src/apps/web/static/oddbean.css @@ -271,6 +271,11 @@ table.vert { color: black; } + .summary > span { + color: #828282; + font-size: 75%; + } + .info { padding-top: 5px; font-size: 75%; diff --git a/src/apps/web/tmpls/feed/item.tmpl b/src/apps/web/tmpls/feed/item.tmpl index 416ecb5..ab8ecbe 100644 --- a/src/apps/web/tmpls/feed/item.tmpl +++ b/src/apps/web/tmpls/feed/item.tmpl @@ -10,7 +10,10 @@
- $!(ctx.ev.summaryHtml()) + $!(ctx.text) + ?(ctx.domain.size()) + ($(ctx.domain)) +