✨ feat(HTML): respect external_links_…
config (#126)
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
{% macro cards_pages(pages) %}
|
||||
|
||||
{%- 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 -%}
|
||||
|
||||
<div class="cards">
|
||||
{%- for page in pages %}
|
||||
<div class="card">
|
||||
{% if page.extra.link_to %}
|
||||
<a rel="noopener noreferrer" target="_blank" href={{ page.extra.link_to }}>
|
||||
<a rel="{{ rel_attributes }}" {{ blank_target }} href={{ 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 @@
|
||||
<div class="card-info">
|
||||
<h1 class="card-title">
|
||||
{% if page.extra.link_to %}
|
||||
<a rel="noopener noreferrer" target="_blank" href={{ page.extra.link_to }}>{{page.title}}</a>
|
||||
<a rel="{{ rel_attributes }}" {{ blank_target }} href={{ page.extra.link_to }}>{{page.title}}</a>
|
||||
{% else %}
|
||||
<a href={{ page.permalink }}>{{page.title}}</a>
|
||||
{% endif %}
|
||||
|
@@ -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 -%}
|
||||
|
||||
<main>
|
||||
<article>
|
||||
@@ -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 %}
|
||||
<li> {{ separator }} <a href="{{ macros_create_history_url::create_history_url(relative_path=page.relative_path) }}" target="_blank" rel="noopener noreferrer">{%- if lang != config.default_language -%}{{ trans(key="see_changes" | safe, lang=lang) }}{% else %}See changes{%- endif -%}<small> ↗</small></a></li>
|
||||
<li> {{ separator }} <a href="{{ macros_create_history_url::create_history_url(relative_path=page.relative_path) }}" {{ blank_target }} rel="{{ rel_attributes }}">{%- if lang != config.default_language -%}{{ trans(key="see_changes" | safe, lang=lang) }}{% else %}See changes{%- endif -%}<small> ↗</small></a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
19
templates/macros/rel_attributes.html
Normal file
19
templates/macros/rel_attributes.html
Normal file
@@ -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 %}
|
Reference in New Issue
Block a user