Pull reading times and word count from Python
This commit is contained in:
parent
a2e44a0a2e
commit
6f3c7a0162
2 changed files with 17 additions and 5 deletions
|
@ -28,10 +28,6 @@ class BasePage(Page):
|
||||||
"""
|
"""
|
||||||
return self.get_ancestors().reverse().exclude(depth__lte=2)
|
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):
|
class BaseContentMixin(models.Model):
|
||||||
subtitle = models.CharField(max_length=255, blank=True)
|
subtitle = models.CharField(max_length=255, blank=True)
|
||||||
|
@ -47,6 +43,18 @@ class BaseContentMixin(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
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]
|
class ContentPage(BasePage, BaseContentMixin): # type: ignore[misc]
|
||||||
subpage_types: list[Any] = []
|
subpage_types: list[Any] = []
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
{% if page.date %}
|
{% if page.date %}
|
||||||
<span title="{{ page.date }}"><i class="far fa-calendar-alt"></i>{{ page.date|date:"Y-m-d" }}</span>
|
<span title="{{ page.date }}"><i class="far fa-calendar-alt"></i>{{ page.date|date:"Y-m-d" }}</span>
|
||||||
{% endif %}
|
{% 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 %}
|
{% 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>
|
<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 %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue