Browse Source

Show content metadata on link topic comments pages

Very basic version - should probably exclude some of the fields (like
domain) and do some other changes in addition to this, but it's a
reasonable start.
merge-requests/85/head
Deimos 5 years ago
parent
commit
ae32c9d600
  1. 29
      tildes/scss/modules/_topic.scss
  2. 5
      tildes/tildes/enums.py
  3. 17
      tildes/tildes/models/topic/topic.py
  4. 17
      tildes/tildes/templates/topic.jinja2

29
tildes/scss/modules/_topic.scss

@ -268,6 +268,35 @@
font-size: 0.6rem;
}
.topic-full-content-metadata {
margin: 1rem 0 1rem 1rem;
h2 {
font-size: 0.8rem;
}
dl {
display: grid;
grid-template-columns: max-content minmax(auto, $paragraph-max-width);
align-items: baseline;
margin: 0;
}
dt {
grid-column-start: 1;
padding: 0.2rem;
font-size: 0.6rem;
}
dd {
grid-column-start: 2;
margin: 0;
padding: 0.2rem;
font-size: 0.6rem;
}
}
.topic-full-tags {
margin-bottom: 0.4rem;
font-size: 0.6rem;

5
tildes/tildes/enums.py

@ -100,6 +100,11 @@ class ContentMetadataFields(enum.Enum):
"""Return the key to store this field under."""
return self.name.lower()
@property
def display_name(self) -> str:
"""Return the field's name in a format more suitable for display."""
return self.name.replace("_", " ").capitalize()
@classmethod
def detail_fields_for_content_type(
cls, content_type: "TopicContentType",

17
tildes/tildes/models/topic/topic.py

@ -519,6 +519,23 @@ class Topic(DatabaseModel):
return ", ".join(metadata_strings)
@property
def content_metadata_fields_for_display(self) -> Dict[str, str]:
"""Return a dict of the metadata fields and values, suitable for display."""
if not self.content_metadata:
return {}
output_fields = {}
for field_name, value in self.content_metadata.items():
try:
field = ContentMetadataFields[field_name.upper()]
except KeyError:
continue
output_fields[field.display_name] = field.format_value(value)
return output_fields
@property
def content_excerpt(self) -> Optional[str]:
"""Return the topic's content excerpt (if it has one)."""

17
tildes/tildes/templates/topic.jinja2

@ -79,6 +79,10 @@
{% if topic.additional_content_html %}
<div class="topic-full-content">{{ topic.additional_content_html|safe }}</div>
{% endif %}
{% if topic.content_metadata %}
{{ content_metadata(topic) }}
{% endif %}
{% endif %}
{% endif %}
@ -300,3 +304,16 @@
{% endif %}
</dl>
{% endblock %}
{% macro content_metadata(topic) %}
<section class="topic-full-content-metadata">
<h2>Link information</h2>
<p class="text-small text-secondary">This data is scraped automatically and may be incorrect.</p>
<dl>
{% for field, value in topic.content_metadata_fields_for_display.items() %}
<dt>{{ field }}</dt>
<dd>{{ value }}</dd>
{% endfor %}
</dl>
</section>
{% endmacro %}
Loading…
Cancel
Save