♻️ refactor: add target_attribute macro

This commit is contained in:
2025-04-28 16:11:01 +07:00
parent cbb52d74a4
commit 74abf0aac6
5 changed files with 15 additions and 15 deletions

View File

@@ -6,6 +6,7 @@
{% import "macros/table_of_contents.html" as macros_toc %} {% import "macros/table_of_contents.html" as macros_toc %}
{% import "macros/translate.html" as macros_translate %} {% import "macros/translate.html" as macros_translate %}
{% import "macros/series_page.html" as macros_series_page %} {% import "macros/series_page.html" as macros_series_page %}
{% import "macros/target_attribute.html" as macros_target_attribute %}
{# Load the internationalisation data for the current language from {# Load the internationalisation data for the current language from
the .toml files in the user's '/i18n' folder, falling back to the theme's. the .toml files in the user's '/i18n' folder, falling back to the theme's.

View File

@@ -0,0 +1,11 @@
{% macro target_attribute(new_tab) %}
{%- set blank_target = "" -%}
{%- if new_tab -%}
{%- set blank_target = "target=_blank" -%}
{%- endif -%}
{{ blank_target }}
{% endmacro target_attribute %}

View File

@@ -5,11 +5,7 @@
{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%} {%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%}
{%- if config.markdown.external_links_target_blank -%} {%- set blank_target = macros_target_attribute::target_attribute(new_tab=config.markdown.external_links_target_blank) -%}
{%- set blank_target = "target=_blank" -%}
{%- else -%}
{%- set blank_target = "" -%}
{%- endif -%}
{# Debugging #} {# Debugging #}
{# <div><pre> {# <div><pre>

View File

@@ -7,11 +7,7 @@
{% break %} {% break %}
{% endif %} {% endif %}
{# Determine which URL to use, default is page.permalink #} {# Determine which URL to use, default is page.permalink #}
{%- if page.extra.link_to and config.markdown.external_links_target_blank -%} {%- set blank_target = macros_target_attribute::target_attribute(new_tab=config.markdown.external_links_target_blank and page.extra.link_to) -%}
{%- set blank_target = "target=_blank" -%}
{%- else -%}
{%- set blank_target = "" -%}
{%- endif -%}
{% set target_url = page.extra.link_to | default(value=page.permalink) %} {% set target_url = page.extra.link_to | default(value=page.permalink) %}

View File

@@ -2,11 +2,7 @@
{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%} {%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%}
{%- if config.markdown.external_links_target_blank -%} {%- set blank_target = macros_target_attribute::target_attribute(new_tab=config.markdown.external_links_target_blank) -%}
{%- set blank_target = "target=_blank" -%}
{%- else -%}
{%- set blank_target = "" -%}
{%- endif -%}
{#- Feed icon -#} {#- Feed icon -#}
{#- Zola 0.19.0 uses `generate_feeds`. Prior versions use `generate_feed` -#} {#- Zola 0.19.0 uses `generate_feeds`. Prior versions use `generate_feed` -#}