Pull reading times and word count from Python

This commit is contained in:
Jake Howard 2022-06-19 21:16:03 +01:00
parent a2e44a0a2e
commit 6f3c7a0162
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 17 additions and 5 deletions

View file

@ -28,10 +28,6 @@ class BasePage(Page):
"""
return self.get_ancestors().reverse().exclude(depth__lte=2)
@cached_property
def table_of_contents(self) -> list[TocEntry]:
return get_table_of_contents()
class BaseContentMixin(models.Model):
subtitle = models.CharField(max_length=255, blank=True)
@ -47,6 +43,18 @@ class BaseContentMixin(models.Model):
class Meta:
abstract = True
@cached_property
def table_of_contents(self) -> list[TocEntry]:
return get_table_of_contents()
@cached_property
def reading_time(self) -> int:
return 4
@cached_property
def word_count(self) -> int:
return 1600
class ContentPage(BasePage, BaseContentMixin): # type: ignore[misc]
subpage_types: list[Any] = []

View file

@ -1,7 +1,11 @@
{% if page.date %}
<span title="{{ page.date }}"><i class="far fa-calendar-alt"></i>{{ page.date|date:"Y-m-d" }}</span>
{% endif %}
<span><i class="far fa-clock"></i>4 minutes</span>
{% if page.reading_time %}
<span title="{{ page.word_count }} words"><i class="far fa-clock"></i>{{ page.reading_time }} minutes</span>
{% endif %}
{% if page.tags.all %}
<span class="is-family-code"><i class="fas fa-tags"></i>{% for tag in page.tags.all %}<a title="{{ tag.name }}">#{{ tag.slug }}</a>{% endfor %}</span>
{% endif %}