mirror of
https://github.com/hoytech/strfry.git
synced 2025-06-20 09:50:28 +00:00
domain
This commit is contained in:
@ -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("<a href=\"") + templarInternal::htmlEscape(firstUrl, true) + "\">" + content + "</a>";
|
||||
}
|
||||
*/
|
||||
|
||||
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);
|
||||
|
@ -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,
|
||||
|
@ -271,6 +271,11 @@ table.vert {
|
||||
color: black;
|
||||
}
|
||||
|
||||
.summary > span {
|
||||
color: #828282;
|
||||
font-size: 75%;
|
||||
}
|
||||
|
||||
.info {
|
||||
padding-top: 5px;
|
||||
font-size: 75%;
|
||||
|
@ -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">
|
||||
|
Reference in New Issue
Block a user