Properly display names, usernames and badges

This commit is contained in:
Zed 2019-06-24 20:45:03 +02:00
parent 6f932b53b0
commit b0b23800e1
4 changed files with 70 additions and 66 deletions

View File

@ -67,46 +67,48 @@ a:hover {
min-width: 0; min-width: 0;
} }
.media-heading a { .media-heading {
display: inline-block;
word-break: break-all;
}
.status-el .media-heading {
padding: 0; padding: 0;
vertical-align: bottom; vertical-align: bottom;
flex-basis: 100%; flex-basis: 100%;
margin-bottom: .2em; margin-bottom: .2em;
} }
.status-el .media-heading .heading-name-row { .media-heading a {
display: inline-block;
word-break: break-all;
max-width: 100%;
}
.heading-name-row {
padding: 0; padding: 0;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
} }
.status-el .media-heading .heading-name-row .name-and-account-name { .fullname-and-username {
display: flex; display: flex;
min-width: 0; min-width: 0;
} }
.status-el .media-heading .heading-name-row .username { .fullname {
flex-shrink: 1;
margin-right: .4em;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
} flex-shrink: 2;
max-width: 80%;
.status-el .username {
white-space: nowrap; white-space: nowrap;
font-size: 14px; font-size: 14px;
overflow: hidden;
flex-shrink: 0;
font-weight: 700; font-weight: 700;
color: #f8f8f2;
} }
.username { .username {
color: #f8f8f2; min-width: 1.6em;
margin-left: .4em;
white-space: nowrap;
word-wrap: normal;
overflow: hidden;
text-overflow: ellipsis;
} }
.verified-icon { .verified-icon {
@ -116,31 +118,34 @@ a:hover {
display: inline-block; display: inline-block;
text-align: center; text-align: center;
vertical-align: middle; vertical-align: middle;
margin-left: 4px;
height: 14px; height: 14px;
width: 14px; width: 14px;
font-size: 10px; font-size: 10px;
margin-bottom: 2px; flex-shrink: 0;
margin: 3px;
margin-top: 2px;
} }
.status-el .media-heading .heading-right { .protected-icon {
color: #fff;
background-color: #353535;
border-radius: 50%;
display: inline-block;
text-align: center;
vertical-align: middle;
height: 18px;
width: 18px;
font-size: 12px;
flex-shrink: 0;
margin: 3px;
margin-top: 2px;
font-weight: bold;
}
.heading-right {
display: flex; display: flex;
flex-shrink: 0; flex-shrink: 0;
} margin-left: 4px;
.status-el .media-heading .heading-name-row .account-name {
min-width: 1.6em;
margin-right: .4em;
flex: 1 1 0;
white-space: nowrap;
word-wrap: normal;
overflow: hidden;
text-overflow: ellipsis;
}
.status-el .media-heading a {
display: inline-block;
word-break: break-all;
} }
.status-el .status-content { .status-el .status-content {
@ -380,6 +385,7 @@ nav {
position: relative; position: relative;
display: flex; display: flex;
justify-content: flex-start; justify-content: flex-start;
max-width: 90%;
} }
.profile-card-tabs { .profile-card-tabs {
@ -387,28 +393,30 @@ nav {
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
flex: 1 1 auto; flex: 1 1 auto;
max-width: 100%;
} }
.profile-card-tabs-name { .profile-card-tabs-name {
padding-top: 0; max-width: 100%;
padding-bottom: 0;
} }
.profile-card-name, .profile-card-username { .profile-card-username, .profile-card-fullname {
color: #f8f8f2; color: #f8f8f2;
} }
.profile-card-name { .profile-card-fullname {
font-size: 16px; font-size: 16px;
word-wrap: break-word;
text-shadow: none; text-shadow: none;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
max-width: 100%;
font-weight: bold;
} }
.profile-card-username { .profile-card-username {
font-size: 14px; font-size: 14px;
overflow: hidden;
text-overflow: ellipsis;
display: block;
} }
.profile-card-avatar { .profile-card-avatar {

View File

@ -17,7 +17,7 @@ proc shortLink*(text: string; length=28): string =
result = result[0 ..< length] & "" result = result[0 ..< length] & ""
proc toLink*(url, text: string; class="timeline-link"): string = proc toLink*(url, text: string; class="timeline-link"): string =
htmlgen.a(text, class=class, href=url) a(text, class=class, href=url)
proc reUrlToLink*(m: RegexMatch; s: string): string = proc reUrlToLink*(m: RegexMatch; s: string): string =
let url = s[m.group(0)[0]] let url = s[m.group(0)[0]]
@ -66,20 +66,16 @@ proc getUserpic*(userpic: string; style=""): string =
proc getUserpic*(profile: Profile; style=""): string = proc getUserpic*(profile: Profile; style=""): string =
getUserPic(profile.userpic, style) getUserPic(profile.userpic, style)
proc formatName*(profile: Profile): string = proc linkUser*(profile: Profile; class=""): string =
result = xmltree.escape(profile.fullname) let
if profile.verified: username = "username" in class
result &= htmlgen.span("", class="verified-icon") href = &"/{profile.username}"
elif profile.protected: text = if username: "@" & profile.username
result &= " 🔒" else: xmltree.escape(profile.fullname)
proc linkUser*(profile: Profile; h: string; username=true; class=""): string = result = a(text, href = href, class = class, title = text)
let text =
if username: "@" & profile.username
else: formatName(profile)
if h.len == 0: if not username and profile.verified:
return htmlgen.a(text, href = &"/{profile.username}", class=class) result &= span("", class="verified-icon", title="Verified account")
if not username and profile.protected:
let element = &"<{h} class=\"{class}\">{text}</{h}>" result &= span("🔒", class="protected-icon", title="Protected account")
htmlgen.a(element, href = &"/{profile.username}")

View File

@ -16,9 +16,9 @@
<div class="media-heading"> <div class="media-heading">
<div class="heading-name-row"> <div class="heading-name-row">
<img class="avatar" src=${tweet.profile.getUserpic("_bigger").getSigUrl("pic")}> <img class="avatar" src=${tweet.profile.getUserpic("_bigger").getSigUrl("pic")}>
<div class="name-and-account-name"> <div class="fullname-and-username">
${linkUser(tweet.profile, "h4", class="username", username=false)} ${linkUser(tweet.profile, class="fullname")}
${linkUser(tweet.profile, "", class="account-name")} ${linkUser(tweet.profile, class="username")}
</div> </div>
<span class="heading-right"> <span class="heading-right">
<a href="${tweet.link}" class="timeago faint-link"> <a href="${tweet.link}" class="timeago faint-link">
@ -46,9 +46,9 @@
</div> </div>
</div> </div>
#end if #end if
<div class="profile-card-name"> <div class="fullname-and-username">
${linkUser(quote.profile, "b", class="username", username=false)} ${linkUser(quote.profile, class="fullname")}
${linkUser(quote.profile, "span", class="account-name")} ${linkUser(quote.profile, class="username")}
</div> </div>
<div class="quote-text">${linkifyText(xmltree.escape(quote.text))}</div> <div class="quote-text">${linkifyText(xmltree.escape(quote.text))}</div>
</div> </div>

View File

@ -12,8 +12,8 @@
</a> </a>
<div class="profile-card-tabs"> <div class="profile-card-tabs">
<div class="profile-card-tabs-name"> <div class="profile-card-tabs-name">
${linkUser(profile, "h1", class="profile-card-name", username=false)} ${linkUser(profile, class="profile-card-fullname")}
${linkUser(profile, "h2", class="profile-card-username")} ${linkUser(profile, class="profile-card-username")}
</div> </div>
</div> </div>
<div class="profile-card-extra"> <div class="profile-card-extra">