✨ feat: add support for social media cards (#130)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{#
|
||||
{#
|
||||
Evaluates the priority of a particular setting across different scopes.
|
||||
|
||||
The priority is as follows: page > section > config.
|
||||
@@ -9,10 +9,12 @@ Parameters:
|
||||
- default_global_value: The setting's default value.
|
||||
#}
|
||||
|
||||
{% macro evaluate_setting_priority(setting, page) %}
|
||||
{% macro evaluate_setting_priority(setting, page, section="", default_global_value="") %}
|
||||
|
||||
{#- Retrieve last ancestor to determine current section, if applicable -#}
|
||||
{%- if page -%}
|
||||
{%- if section -%}
|
||||
{%- set current_section = section -%}
|
||||
{%- elif page -%}
|
||||
{#- Retrieve last ancestor to determine current section, if applicable -#}
|
||||
{%- set last_ancestor = page.ancestors | slice(start=-1) %}
|
||||
{%- set current_section = get_section(path=last_ancestor.0) %}
|
||||
{%- endif -%}
|
||||
@@ -20,17 +22,14 @@ Parameters:
|
||||
{%- set priority_order = [
|
||||
page.extra[setting] | default(value=""),
|
||||
current_section.extra[setting] | default(value=""),
|
||||
config.extra[setting] | default(value=default_global_value)
|
||||
config.extra[setting] | default(value="")
|
||||
] -%}
|
||||
|
||||
{%- set output = "false" -%}
|
||||
{%- set output = default_global_value -%}
|
||||
|
||||
{%- for value in priority_order -%}
|
||||
{%- if value == true -%}
|
||||
{%- set_global output = "true" -%}
|
||||
{%- break -%}
|
||||
{%- elif value == false -%}
|
||||
{%- set_global output = "false" -%}
|
||||
{%- if value != "" -%}
|
||||
{%- set_global output = value -%}
|
||||
{%- break -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
@@ -51,31 +51,33 @@
|
||||
<link rel="stylesheet" href="{{ get_url(path=stylesheet, cachebust=true) | safe }}" />
|
||||
{%- endfor %}
|
||||
|
||||
<meta name="color-scheme" content="{%- if config.extra.theme_switcher -%}light dark{%- elif config.extra.default_theme -%}{{config.extra.default_theme}}{%- else -%}light{%- endif -%}">
|
||||
<meta name="color-scheme" content="{%- if config.extra.theme_switcher -%}light dark{%- elif config.extra.default_theme -%}{{config.extra.default_theme}}{%- else -%}light{%- endif -%}" />
|
||||
|
||||
{%- if page.description %}
|
||||
<meta name="description" content="{{ page.description | striptags | safe }}" />
|
||||
<meta property="og:description" content="{{ page.description | striptags | safe }}">
|
||||
<meta property="og:description" content="{{ page.description | striptags | safe }}" />
|
||||
{%- elif page.summary %}
|
||||
<meta name="description" content="{{ page.summary | striptags | safe | trim_end_matches(pat=".") }}…" />
|
||||
<meta property="og:description" content="{{ page.summary | striptags | safe | trim_end_matches(pat=".") }}…">
|
||||
<meta property="og:description" content="{{ page.summary | striptags | safe | trim_end_matches(pat=".") }}…" />
|
||||
{%- else %}
|
||||
<meta name="description" content="{{ config.description }}" />
|
||||
<meta property="og:description" content="{{ config.description }}">
|
||||
<meta property="og:description" content="{{ config.description }}" />
|
||||
{%- endif %}
|
||||
|
||||
{% if is_404 %}
|
||||
<meta name="robots" content="noindex, follow">
|
||||
<meta name="robots" content="noindex, follow" />
|
||||
{% else %}
|
||||
<meta name="robots" content="index, nofollow">
|
||||
<meta name="robots" content="index, nofollow" />
|
||||
{% endif %}
|
||||
|
||||
<meta property="og:title" content="{{ config.title }}">
|
||||
<meta property="og:title" content="{{ config.title }}" />
|
||||
<meta property="og:type" content="article" />
|
||||
|
||||
{% if config.extra.headerImage %}
|
||||
<meta property="og:image" content="{{ config.extra.headerImage }}">
|
||||
<meta name="twitter:card" content="{{ config.extra.headerImage }}">
|
||||
{# Image for social media sharing #}
|
||||
{%- set social_media_card = macros_settings::evaluate_setting_priority(setting="social_media_card", page=page | default(value=""), section=section | default(value=""), default_global_value="") -%}
|
||||
{% if social_media_card %}
|
||||
<meta property="og:image" content="{{ get_url(path=social_media_card, cachebust=true) }}" />
|
||||
<meta name="twitter:card" content="summary_large_image" />
|
||||
{% endif %}
|
||||
|
||||
{% set current_url = current_url | default(value="/") %}
|
||||
|
Reference in New Issue
Block a user