Browse Source

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.
merge-requests/85/head
Deimos 5 years ago
parent
commit
a76955011f
  1. 14
      tildes/tildes/models/topic/topic.py
  2. 2
      tildes/tildes/templates/macros/topics.jinja2

14
tildes/tildes/models/topic/topic.py

@ -408,15 +408,16 @@ class Topic(DatabaseModel):
return False 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.""" """Return the content's type based on the topic's attributes."""
if self.is_text_type: if self.is_text_type:
if self.has_tag("ask"): if self.has_tag("ask"):
return TopicContentType.ASK return TopicContentType.ASK
return TopicContentType.TEXT return TopicContentType.TEXT
else:
if self.is_link_type:
parsed_url = urlparse(self.link) # type: ignore parsed_url = urlparse(self.link) # type: ignore
url_path = PurePosixPath(parsed_url.path) url_path = PurePosixPath(parsed_url.path)
@ -435,7 +436,12 @@ class Topic(DatabaseModel):
except IndexError: except IndexError:
pass 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: def get_content_metadata(self, key: str) -> Any:
"""Get a piece of content metadata "safely". """Get a piece of content metadata "safely".

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

@ -46,7 +46,7 @@
</ul> </ul>
{% endif %} {% 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 %} {% if topic.content_metadata_for_display %}
<span class="topic-content-metadata">: {{ topic.content_metadata_for_display }}</span> <span class="topic-content-metadata">: {{ topic.content_metadata_for_display }}</span>

Loading…
Cancel
Save