Skip to content

Commit

Permalink
domain
Browse files Browse the repository at this point in the history
  • Loading branch information
hoytech committed Dec 18, 2024
1 parent a270f5d commit 8b6f076
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
34 changes: 30 additions & 4 deletions src/apps/web/WebData.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()) {
Expand All @@ -262,8 +287,9 @@ struct Event {
return std::string("<a href=\"") + templarInternal::htmlEscape(firstUrl, true) + "\">" + content + "</a>";
}
*/

return content;
return output;
}


Expand Down Expand Up @@ -520,7 +546,7 @@ struct EventThread {
if (p == eventCache.end()) return "";

const auto &elem = p->second;
return elem.summaryHtml(false);
return elem.summaryHtml().text;
}


Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/apps/web/WebReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/apps/web/static/oddbean.css
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ table.vert {
color: black;
}

.summary > span {
color: #828282;
font-size: 75%;
}

.info {
padding-top: 5px;
font-size: 75%;
Expand Down
5 changes: 4 additions & 1 deletion src/apps/web/tmpls/feed/item.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

<div class="right">
<div class="summary">
<a href="/e/$(ctx.ev.getNoteId())">$!(ctx.ev.summaryHtml())</a>
<a href="$(ctx.url)">$!(ctx.text)</a>
<span> ?(ctx.domain.size())
($(ctx.domain))
</span>
</div>

<div class="info">
Expand Down

0 comments on commit 8b6f076

Please sign in to comment.