mirror of
https://gitlab.com/tildes/tildes.git
synced 2026-04-17 06:48:36 +02:00
Use "Link" as the default content type for links
Previously a topic with an unknown content type would display "Article". This switches to "Link" which will have some different idiosyncracies, but should be a little more correct in general.
This commit is contained in:
@@ -408,15 +408,16 @@ class Topic(DatabaseModel):
|
||||
|
||||
return False
|
||||
|
||||
@property
|
||||
def content_type(self) -> TopicContentType:
|
||||
@property # noqa
|
||||
def content_type(self) -> Optional[TopicContentType]:
|
||||
"""Return the content's type based on the topic's attributes."""
|
||||
if self.is_text_type:
|
||||
if self.has_tag("ask"):
|
||||
return TopicContentType.ASK
|
||||
|
||||
return TopicContentType.TEXT
|
||||
else:
|
||||
|
||||
if self.is_link_type:
|
||||
parsed_url = urlparse(self.link) # type: ignore
|
||||
url_path = PurePosixPath(parsed_url.path)
|
||||
|
||||
@@ -435,7 +436,12 @@ class Topic(DatabaseModel):
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
return TopicContentType.ARTICLE
|
||||
# consider it an article if we picked up a word count of at least 200
|
||||
word_count = self.get_content_metadata("word_count")
|
||||
if word_count and word_count >= 200:
|
||||
return TopicContentType.ARTICLE
|
||||
|
||||
return None
|
||||
|
||||
def get_content_metadata(self, key: str) -> Any:
|
||||
"""Get a piece of content metadata "safely".
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
||||
<span class="topic-content-type">{{ topic.content_type.display_name }}</span>
|
||||
<span class="topic-content-type">{{ topic.content_type.display_name if topic.content_type else "Link" }}</span>
|
||||
|
||||
{% if topic.content_metadata_for_display %}
|
||||
<span class="topic-content-metadata">: {{ topic.content_metadata_for_display }}</span>
|
||||
|
||||
Reference in New Issue
Block a user