Add template caching for listing components
This commit is contained in:
parent
6775a336e1
commit
23b8454fe4
4 changed files with 45 additions and 33 deletions
|
@ -68,6 +68,8 @@ exclude = '''
|
||||||
| referrallink_snippet_link\.html
|
| referrallink_snippet_link\.html
|
||||||
| onlineaccount_snippet_link\.html
|
| onlineaccount_snippet_link\.html
|
||||||
| 500\.html
|
| 500\.html
|
||||||
|
| content-details\.html
|
||||||
|
| listing-item\.html
|
||||||
)
|
)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,36 @@
|
||||||
{% load wagtailcore_tags humanize_tags %}
|
{% load wagtailcore_tags humanize_tags cache util_tags %}
|
||||||
|
|
||||||
<div class="content-details field is-grouped">
|
{% cache 600|jitter:60 "content-details" page.id request.is_preview %}
|
||||||
|
<div class="content-details field is-grouped">
|
||||||
{% if page.date %}
|
{% if page.date %}
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
<i class="far fa-lg fa-calendar-alt"></i>
|
<i class="far fa-lg fa-calendar-alt"></i>
|
||||||
|
</span>
|
||||||
|
<span>{{ page.date|date:"Y-m-d" }}</span>
|
||||||
</span>
|
</span>
|
||||||
<span>{{ page.date|date:"Y-m-d" }}</span>
|
{% endif %}
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if page.show_reading_time %}
|
{% if page.show_reading_time %}
|
||||||
<div class="icon-text" {% if page.word_count %}title="{{ page.word_count }} words"{% endif %}>
|
<div class="icon-text" {% if page.word_count %}title="{{ page.word_count }} words"{% endif %}>
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
<i class="far fa-lg fa-clock"></i>
|
<i class="far fa-lg fa-clock"></i>
|
||||||
</span>
|
</span>
|
||||||
<span>{{ page.reading_time|naturaldelta }}</span>
|
<span>{{ page.reading_time|naturaldelta }}</span>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page.tags.all %}
|
{% if page.tags.all %}
|
||||||
<div class="icon-text is-family-code">
|
<div class="icon-text is-family-code">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
<a href="{{ page.tag_list_page_url }}" title="View all tags">
|
<a href="{{ page.tag_list_page_url }}" title="View all tags">
|
||||||
<i class="fas fa-lg fa-tags"></i>
|
<i class="fas fa-lg fa-tags"></i>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
{% for tag in page.tags.all %}
|
{% for tag in page.tags.all %}
|
||||||
<span><a title="{{ tag.name }}" href="{% pageurl tag %}">#{{ tag.slug }}</a></span>
|
<span><a title="{{ tag.name }}" href="{% pageurl tag %}">#{{ tag.slug }}</a></span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endcache %}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% load wagtailcore_tags %}
|
{% load wagtailcore_tags cache util_tags %}
|
||||||
|
|
||||||
<article class="media listing-item">
|
<article class="media listing-item">
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
|
@ -13,7 +13,9 @@
|
||||||
<div>
|
<div>
|
||||||
<h2 class="title is-3"><a href="{% pageurl page %}">{{ page.title }}</a></h2>
|
<h2 class="title is-3"><a href="{% pageurl page %}">{{ page.title }}</a></h2>
|
||||||
{% include "common/content-details.html" %}
|
{% include "common/content-details.html" %}
|
||||||
<p>{{ page.summary }}</p>
|
{% cache 900|jitter:60 "summary" page.id request.is_preview %}
|
||||||
|
<p>{{ page.summary }}</p>
|
||||||
|
{% endcache %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import random
|
||||||
|
|
||||||
from django.template import Library
|
from django.template import Library
|
||||||
from django.utils.encoding import force_str
|
from django.utils.encoding import force_str
|
||||||
from wagtail.models import Page
|
from wagtail.models import Page
|
||||||
|
@ -18,6 +20,11 @@ def pagefullurl(context: dict, page: Page) -> str:
|
||||||
return page.get_full_url(context["request"])
|
return page.get_full_url(context["request"])
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter()
|
||||||
|
def jitter(original: float, jitter: float) -> float:
|
||||||
|
return random.uniform(original + jitter, original - jitter)
|
||||||
|
|
||||||
|
|
||||||
@register.filter()
|
@register.filter()
|
||||||
def extract_text(html: str | RichText) -> str:
|
def extract_text(html: str | RichText) -> str:
|
||||||
return utils.extract_text(force_str(html))
|
return utils.extract_text(force_str(html))
|
||||||
|
|
Loading…
Reference in a new issue