Skip to content

Commit

Permalink
fix(pwa): cache post list paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesrocket committed Apr 25, 2024
1 parent 90ce729 commit 43e6d21
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions templates/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,16 @@
<link rel="stylesheet" type="text/css" href="{{ get_url(path="/syntax-theme-dark.css", cachebust=true) }}" media="(prefers-color-scheme: dark)" integrity="sha512-{{ get_hash(path="/syntax-theme-dark.css", sha_type=512, base64=true) | safe }}">
{%- endif %}
{%- if config.extra.manifest %}
{%- set posts = get_section(path="posts/_index.md") %}
<script defer src="{{ get_url(path='sw-load.js', trailing_slash=false, cachebust=true) | safe }}" integrity="sha512-{{ get_hash(path='sw-load.js', sha_type=512, base64=true) | safe }}" data-cache="{% if config.taxonomies %}{% for taxonomy in config.taxonomies %}{% set inner_taxonomy = get_taxonomy(kind=taxonomy.name) %}{{ inner_taxonomy.permalink | safe }} {% for term in inner_taxonomy.items %}{{ term.permalink | safe }} {% endfor %}{% endfor %}{% endif %}{% for post in posts.pages %}{{ post.permalink | safe }} {% if post.assets %}{% for asset in post.assets %}{{ config.base_url ~ asset | safe }} {% endfor %}{%endif%}{% endfor %}{% for link in config.extra.menu.links %}{{ get_url(path=link.url, cachebust=true) | safe }} {% endfor %}{% if config.extra.menu.posts == true %}{{ config.base_url ~ "/posts/" | safe }} {% endif %}{% for link in config.extra.images.categories %}{% if link.image is not matching("^http[s]?://") %}{{ get_url(path=link.image, cachebust=true) | safe }} {% endif %}{% endfor %}{% if config.extra.images.home is not matching("^http[s]?://") %}{{ get_url(path=config.extra.images.home, cachebust=true) | safe }} {% endif %}{% if config.extra.images.post_list is not matching("^http[s]?://") %}{{ get_url(path=config.extra.images.post_list, cachebust=true) | safe }} {% endif %}{% if config.extra.images.default_post is not matching("^http[s]?://") %}{{ get_url(path=config.extra.images.default_post, cachebust=true) | safe }} {% endif %}{{ get_url(path="/main.css", cachebust=true) | safe }} {{ get_url(path="/nerd-fonts.css", cachebust=true) | safe }} {{ get_url(path=config.extra.logo, cachebust=true) | safe }} {{ get_url(path="/syntax-theme-light.css", cachebust=true) | safe }} {{ get_url(path="/syntax-theme-dark.css", cachebust=true) | safe }} {{ get_url(path="/unstyle.css", cachebust=true) | safe }} {{ get_url(path="/langs.css", cachebust=true) | safe }}{% if config.extra.home.glitch %} {{ get_url(path="/glitch.css", cachebust=true) | safe }}{% endif %}{% if config.build_search_index == true %} {{ get_url(path="/search.js", cachebust=true) | safe }} {{ get_url(path="/elasticlunr.min.js", cachebust=true) | safe }}{% endif %}"></script>
{% if config.extra.menu.posts == true %}
{% set posts = get_section(path="posts/_index.md") %}
{% set raw_posts_config = load_data(path="/posts/_index.md", format="plain") | replace(from="+++", to="") %}
{% set posts_config = load_data(literal=raw_posts_config, format="toml") %}
{% set post_count = posts.pages | length %}
{% if posts_config.paginate_by %}
{% set page_count = post_count / posts_config.paginate_by | round(method="ceil") | int | default(value=0) %}
{% endif %}
{% endif %}
<script defer src="{{ get_url(path='sw-load.js', trailing_slash=false, cachebust=true) | safe }}" integrity="sha512-{{ get_hash(path='sw-load.js', sha_type=512, base64=true) | safe }}" data-cache="{% if posts_config.paginate_by %}{% for i in range(start=2, end=page_count + 1) %}{{ config.base_url ~ "/posts/page/" ~ i ~ "/" | safe }} {% endfor %}{% endif %}{% if config.taxonomies %}{% for taxonomy in config.taxonomies %}{% set inner_taxonomy = get_taxonomy(kind=taxonomy.name) %}{{ inner_taxonomy.permalink | safe }} {% for term in inner_taxonomy.items %}{{ term.permalink | safe }} {% endfor %}{% endfor %}{% endif %}{% for post in posts.pages %}{{ post.permalink | safe }} {% if post.assets %}{% for asset in post.assets %}{{ config.base_url ~ asset | safe }} {% endfor %}{%endif%}{% endfor %}{% for link in config.extra.menu.links %}{{ get_url(path=link.url, cachebust=true) | safe }} {% endfor %}{% if config.extra.menu.posts == true %}{{ config.base_url ~ "/posts/" | safe }} {% endif %}{% for link in config.extra.images.categories %}{% if link.image is not matching("^http[s]?://") %}{{ get_url(path=link.image, cachebust=true) | safe }} {% endif %}{% endfor %}{% if config.extra.images.home is not matching("^http[s]?://") %}{{ get_url(path=config.extra.images.home, cachebust=true) | safe }} {% endif %}{% if config.extra.images.post_list is not matching("^http[s]?://") %}{{ get_url(path=config.extra.images.post_list, cachebust=true) | safe }} {% endif %}{% if config.extra.images.default_post is not matching("^http[s]?://") %}{{ get_url(path=config.extra.images.default_post, cachebust=true) | safe }} {% endif %}{{ get_url(path="/main.css", cachebust=true) | safe }} {{ get_url(path="/nerd-fonts.css", cachebust=true) | safe }} {{ get_url(path=config.extra.logo, cachebust=true) | safe }} {{ get_url(path="/syntax-theme-light.css", cachebust=true) | safe }} {{ get_url(path="/syntax-theme-dark.css", cachebust=true) | safe }} {{ get_url(path="/unstyle.css", cachebust=true) | safe }} {{ get_url(path="/langs.css", cachebust=true) | safe }}{% if config.extra.home.glitch %} {{ get_url(path="/glitch.css", cachebust=true) | safe }}{% endif %}{% if config.build_search_index == true %} {{ get_url(path="/search.js", cachebust=true) | safe }} {{ get_url(path="/elasticlunr.min.js", cachebust=true) | safe }}{% endif %}"></script>
{%- endif %}
{%- if page.extra.image %}
<style>{{ macros::image_style(url=page.extra.image) }}</style>
Expand Down

0 comments on commit 43e6d21

Please sign in to comment.