Skip to content

Commit

Permalink
refactor: blog card post placeholder handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow committed Oct 28, 2024
1 parent b80d369 commit 03c7dc4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
5 changes: 4 additions & 1 deletion mkdocs_nype/plugins/nype_tweaks/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
6. Create nype_config for page and sync with global tweak:
This was previously done at render time in nype-base.html, but this is too late
for blog cards meta placeholders. To use the global value for the placeholder
better set it in the event.
better set it in the event. Errata: Turned out this train of thought was wrong,
as the posts' on_page events run after the blog index with the cards, so the
tweak doesn't make things easier. Global placeholder loading was moved to the
post-card.html template.
MIT License 2024 Kamil Krzyśków (HRY) for Nype (npe.cm)
"""
Expand Down
55 changes: 28 additions & 27 deletions mkdocs_nype/templates/partials/post-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,42 @@
{#- nype_config of the Excerpt can contain overrides to some values -#}
{% set post_nype_config = post.meta.nype_config or {} -%}

{# store category separately for easier access later #}
{# Store category separately for easier access later #}
{% if blog_card_category_view -%}
{% set blog_card_category = blog_card_category_view -%}
{% elif post.meta.categories -%}
{% set blog_card_category = post.meta.categories[0].strip() -%}
{% endif -%}

{# resolve category icon for card #}
{% if post_nype_config.blog_card_icon -%}
{% set blog_card_icon = post_nype_config.blog_card_icon -%}
{% elif blog_card_icons -%}
{% set blog_card_icon = blog_card_icons.get(blog_card_category, blog_card_icons._default) -%}
{% endif -%}
{# Resolve category icon for card #}
{% set blog_card_icon = post_nype_config.blog_card_icon or blog_card_icons.get(blog_card_category, blog_card_icons._default) or "material/file-document" -%}

{#- Resolve page title -#}
{% set blog_card_title = post_nype_config.blog_card_title or theme_nype_config.blog_card_title -%}

{% if not blog_card_icon -%}
{% set blog_card_icon = "material/file-document" -%}
{% if blog_card_title -%}
{% set blog_card_title = blog_card_title.format(post_title=post.post.title) -%}
{% else -%}
{% set blog_card_title = post | post_card_title -%}
{% endif -%}

{# resolve page read more prompt #}
{% if post_nype_config.blog_card_continue -%}
{% set blog_card_continue = post_nype_config.blog_card_continue -%}
{% elif blog_card_continues %}
{% set blog_card_continue = blog_card_continues.get(blog_card_category, blog_card_continues._default) -%}
{#- Resolve page description -#}
{% set blog_card_description = post_nype_config.blog_card_description or theme_nype_config.blog_card_description -%}

{% if blog_card_description -%}
{% set blog_card_description = '<p>' ~ blog_card_description.format(post_description=post.meta.description) ~ '</p>' -%}
{% else -%}
{% set blog_card_description = post | post_card_description -%}

{# Resolve page read more prompt #}
{% set blog_card_continue = post_nype_config.blog_card_continue or blog_card_continues.get(blog_card_category, blog_card_continues._default)-%}

{% if blog_card_continue -%}
{% set blog_card_continue = blog_card_continue.format(category=blog_card_category) -%}
{% else -%}
{% set blog_card_continue = lang.t("blog.continue") -%}
{% endif -%}

{% if not blog_card_continue -%}
{% set blog_card_continue = lang.t("blog.continue") -%}
{% endif -%}

<!-- Post excerpt card -->
Expand All @@ -75,28 +84,20 @@
{% include ".icons/" ~ blog_card_icon ~ ".svg" -%}
</span>
<strong>
{% if post_nype_config.blog_card_title -%}
{{ post_nype_config.blog_card_title.format(post_title=post.post.title) -}}
{% else -%}
{{ post | post_card_title -}}
{% endif -%}
{{- blog_card_title -}}
</strong>
</p>

<hr>

{% if post_nype_config.blog_card_description -%}
<p>{{ post_nype_config.blog_card_description.format(post_description=post.meta.description) }}</p>
{% else %}
{{ post | post_card_description -}}
{% endif %}
{{ blog_card_description -}}

<!-- Continue reading link -->
{% if post.more and (blog_cards != "off" or not hide_read_more) %}
<nav class="md-post__action">
<a href="{{ post.url | url }}">
<span class="twemoji">{% include ".icons/octicons/arrow-right-24.svg" %}</span>
{{ blog_card_continue.format(category=blog_card_category) -}}
{{ blog_card_continue -}}
</a>
</nav>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "hatchling.build"

[project]
name = "mkdocs-nype"
version = "0.18.2"
version = "0.19.0"
description = "MkDocs theme for Nype MkDocs projects, extends the Material for MkDocs theme"
authors = [
{ name = "Kamil Krzyśków", email = "[email protected]" }
Expand Down

0 comments on commit 03c7dc4

Please sign in to comment.