Ver código fonte

Display content attribution

Zed 6 anos atrás
pai
commit
0b5c15ce67
4 arquivos alterados com 35 adições e 1 exclusões
  1. 8 0
      src/parserutils.nim
  2. 18 1
      src/sass/tweet/_base.scss
  3. 1 0
      src/types.nim
  4. 8 0
      src/views/tweet.nim

+ 8 - 0
src/parserutils.nim

@@ -199,6 +199,14 @@ proc getTweetMedia*(tweet: Tweet; node: XmlNode) =
   let player = node.select(".PlayableMedia")
   if player == nil: return
 
+  let attrib = player.select(".PlayableMedia-attribution")
+  if attrib != nil:
+    tweet.attribution = some Profile(
+      username: attrib.attr("href").strip(chars={'/'}),
+      fullname: attrib.selectText(".fullname"),
+      userpic: attrib.selectAttr(".avatar", "src")
+    )
+
   if "gif" in player.attr("class"):
     tweet.gif = some getGif(player.select(".PlayableMedia-player"))
   elif "video" in player.attr("class"):

+ 18 - 1
src/sass/tweet/_base.scss

@@ -88,7 +88,24 @@
         margin-left: -58px;
         width: 48px;
         height: 48px;
-        border-radius: 50%;
+    }
+}
+
+.avatar {
+    border-radius: 50%;
+}
+
+.attribution {
+    display: flex;
+    pointer-events: all;
+    margin: 10px 0;
+
+    .avatar {
+        margin-right: 5px;
+    }
+
+    strong {
+        color: var(--fg_color);
     }
 }
 

+ 1 - 0
src/types.nim

@@ -148,6 +148,7 @@ type
     tombstone*: string
     stats*: TweetStats
     retweet*: Option[Retweet]
+    attribution*: Option[Profile]
     quote*: Option[Quote]
     card*: Option[Card]
     gif*: Option[Gif]

+ 8 - 0
src/views/tweet.nim

@@ -188,6 +188,11 @@ proc renderReply(quote: Quote): VNode =
       if i > 0: text " "
       a(href=("/" & u)): text "@" & u
 
+proc renderAttribution(profile: Profile): VNode =
+  buildHtml(a(class="attribution", href=("/" & profile.username))):
+    img(class="avatar", width="20", height="20", src=profile.getUserpic("_200x200"))
+    strong: text profile.fullname
+
 proc renderQuoteMedia(quote: Quote): VNode =
   buildHtml(tdiv(class="quote-media-container")):
     if quote.thumb.len > 0:
@@ -258,6 +263,9 @@ proc renderTweet*(tweet: Tweet; prefs: Prefs; path: string; class="";
       tdiv(class="tweet-content media-body", dir="auto"):
         verbatim replaceUrl(tweet.text, prefs)
 
+      if tweet.attribution.isSome:
+        renderAttribution(tweet.attribution.get())
+
       if tweet.quote.isSome:
         renderQuote(tweet.quote.get(), prefs)