Browse Source

Replace domain with more info for YouTube+Twitter

In topic listings, when a link topic is from YouTube or Twitter, this
will now display more info about the "source" instead of just the
domain. For YouTube, the channel name is displayed, and for Twitter, the
author of the tweet is displayed.
merge-requests/68/head
Deimos 6 years ago
parent
commit
78e09f05b1
  1. 20
      tildes/tildes/models/topic/topic.py
  2. 2
      tildes/tildes/templates/macros/topics.jinja2

20
tildes/tildes/models/topic/topic.py

@ -361,6 +361,26 @@ class Topic(DatabaseModel):
# parsing it from the link if it's not present # parsing it from the link if it's not present
return self.get_content_metadata("domain") or get_domain_from_url(self.link) return self.get_content_metadata("domain") or get_domain_from_url(self.link)
@property
def link_source(self) -> str:
"""Return the link's "source", which can be defined for certain domains.
If special behavior isn't defined for a domain, this just falls back to
returning the domain itself.
"""
if not self.is_link_type:
raise ValueError("Non-link topics do not have a link source")
domain = self.link_domain
authors = self.get_content_metadata("authors")
if domain == "twitter.com" and authors:
return f"Twitter: @{authors[0]}"
elif domain == "youtube.com" and authors:
return f"YouTube: {authors[0]}"
return domain
@property @property
def is_spoiler(self) -> bool: def is_spoiler(self) -> bool:
"""Return whether the topic is marked as a spoiler.""" """Return whether the topic is marked as a spoiler."""

2
tildes/tildes/templates/macros/topics.jinja2

@ -83,7 +83,7 @@
{% if topic.is_user_treated_as_source %} {% if topic.is_user_treated_as_source %}
aria-label="Posted by">{{ username_linked(topic.user.username) }} aria-label="Posted by">{{ username_linked(topic.user.username) }}
{% else %} {% else %}
aria-label="Link domain">{{ topic.link_domain }}
aria-label="Link source">{{ topic.link_source }}
{% endif %} {% endif %}
</div> </div>

Loading…
Cancel
Save