From b73f7f5d931a3212bfd7fdbd52170ebf5f4b03f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar?= Date: Wed, 30 Aug 2023 01:38:27 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(HTML):=20respect=20`external?= =?UTF-8?q?=5Flinks=5F=E2=80=A6`=20config=20(#126)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/base.html | 15 ++++++++------- templates/macros/cards_pages.html | 12 ++++++++++-- templates/macros/content.html | 12 ++++++++++-- templates/macros/rel_attributes.html | 19 +++++++++++++++++++ templates/partials/footer.html | 25 +++++++++++++++++-------- 5 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 templates/macros/rel_attributes.html diff --git a/templates/base.html b/templates/base.html index 4fdbf8a..357ceed 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,14 +1,15 @@ +{% import "macros/add_comments.html" as macros_add_comments %} +{% import "macros/cards_pages.html" as macros_cards_pages %} +{% import "macros/content.html" as macros_content %} +{% import "macros/create_history_url.html" as macros_create_history_url %} +{% import "macros/format_date.html" as macros_format_date %} {% import "macros/list_posts.html" as macros_list_posts %} -{% import "macros/page_header.html" as macros_page_header %} {% import "macros/page_desc.html" as macros_page_desc %} -{% import "macros/content.html" as macros_content %} -{% import "macros/cards_pages.html" as macros_cards_pages %} -{% import "macros/set_title.html" as macros_set_title %} +{% import "macros/page_header.html" as macros_page_header %} {% import "macros/paginate.html" as macros_paginate %} -{% import "macros/format_date.html" as macros_format_date %} -{% import "macros/add_comments.html" as macros_add_comments %} +{% import "macros/rel_attributes.html" as macros_rel_attributes %} +{% import "macros/set_title.html" as macros_set_title %} {% import "macros/table_of_contents.html" as macros_toc %} -{% import "macros/create_history_url.html" as macros_create_history_url %} {%- for page in pages %}
{% if page.extra.link_to %} - + {% endif %} {% if page.extra.local_image %} {% set meta = get_image_metadata(path=page.extra.local_image, allow_missing=true) %} @@ -21,7 +29,7 @@

{% if page.extra.link_to %} - {{page.title}} + {{page.title}} {% else %} {{page.title}} {% endif %} diff --git a/templates/macros/content.html b/templates/macros/content.html index 4c42835..9a45f5b 100644 --- a/templates/macros/content.html +++ b/templates/macros/content.html @@ -1,6 +1,14 @@ {% macro content(page) %} -{% set separator = config.extra.separator | default(value="•") %} +{%- set separator = config.extra.separator | default(value="•") -%} + +{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%} + +{%- if config.markdown.external_links_target_blank -%} + {%- set blank_target = "target=_blank" -%} +{%- else -%} + {%- set blank_target = "" -%} +{%- endif -%}
@@ -35,7 +43,7 @@ {# Show link to remote changes if enabled #} {% set show_remote_changes = config.extra.show_remote_changes | default(value=true) %} {% if config.extra.remote_repository_url and show_remote_changes %} -
  •  {{ separator }} {%- if lang != config.default_language -%}{{ trans(key="see_changes" | safe, lang=lang) }}{% else %}See changes{%- endif -%}
  • +
  •  {{ separator }} {%- if lang != config.default_language -%}{{ trans(key="see_changes" | safe, lang=lang) }}{% else %}See changes{%- endif -%}
  • {% endif %} {% endif %} diff --git a/templates/macros/rel_attributes.html b/templates/macros/rel_attributes.html new file mode 100644 index 0000000..0fab687 --- /dev/null +++ b/templates/macros/rel_attributes.html @@ -0,0 +1,19 @@ +{% macro rel_attributes() %} + +{%- set rel_attributes = [] -%} +{%- if config.markdown.external_links_target_blank -%} + {%- set rel_attributes = rel_attributes | concat(with="noopener") -%} +{%- endif -%} +{# https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/rel#nofollow #} +{# This is ignored, as it doesn't make sense to set `nofollow` on projects or social links. #} +{# {%- if config.markdown.external_links_no_follow -%} + {%- set rel_attributes = rel_attributes | concat(with="nofollow") -%} +{%- endif -%} #} +{%- if config.markdown.external_links_no_referrer -%} + {%- set rel_attributes = rel_attributes | concat(with="noreferrer") -%} +{%- endif -%} + +{# Return the array of rel attributes joined by a space #} +{{- rel_attributes | join(sep=" ") -}} + +{% endmacro external_links %} diff --git a/templates/partials/footer.html b/templates/partials/footer.html index 439d089..7f28de0 100644 --- a/templates/partials/footer.html +++ b/templates/partials/footer.html @@ -1,4 +1,13 @@ -{% set separator = config.extra.separator | default(value="•") %} +{%- set separator = config.extra.separator | default(value="•") -%} + +{%- set rel_attributes = macros_rel_attributes::rel_attributes() | trim -%} + +{%- if config.markdown.external_links_target_blank -%} + {%- set blank_target = "target=_blank" -%} +{%- else -%} + {%- set blank_target = "" -%} +{%- endif -%} +