feat: add support for social media cards

Can be set at the post, section and `config.toml`.
It respects the hierarchy post > section > config. See #128
This commit is contained in:
welpo 2023-09-03 21:22:55 +02:00
parent e241601f7c
commit 2e75ac7b74
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
3 changed files with 15 additions and 7 deletions

View file

@ -222,8 +222,11 @@ favicon = "img/seedling.png"
# Compatibility: https://caniuse.com/link-icon-svg # Compatibility: https://caniuse.com/link-icon-svg
favicon_emoji = "🌱" favicon_emoji = "🌱"
# This header image is used for SEO. For example if you were to share an image via Messenger/Instagram/Twitter a preview picture is also presented # Path to the fallback image for social media cards (the image shown when sharing a link on WhatsApp, LinkedIn…).
headerImage = "" # Read more: https://nikitahl.com/html-meta-tags-for-social-media
# Using an image representative of each post is recommended. You can do so by setting this variable in the [extra] section of a post's front matter.
# If a post doesn't have a social media card, the site's default, below, will be used.
social_media_card_path = ""
menu = [ menu = [
{ name = "blog", url = "blog", trailing_slash = true }, { name = "blog", url = "blog", trailing_slash = true },

View file

@ -73,9 +73,11 @@
<meta property="og:title" content="{{ config.title }}"> <meta property="og:title" content="{{ config.title }}">
<meta property="og:type" content="article" /> <meta property="og:type" content="article" />
{% if config.extra.headerImage %} {# Image for social media sharing #}
<meta property="og:image" content="{{ config.extra.headerImage }}"> {%- set social_media_card = macros_settings::evaluate_setting_priority(setting="social_media_card", page=page | default(value=""), default_global_value="") -%}
<meta name="twitter:card" content="{{ config.extra.headerImage }}"> {% if social_media_card %}
<meta property="og:image" content="{{ get_url(path=social_media_card) }}">
<meta name="twitter:card" content="{{ get_url(path=social_media_card) }}">
{% endif %} {% endif %}
{% set current_url = current_url | default(value="/") %} {% set current_url = current_url | default(value="/") %}

View file

@ -107,8 +107,11 @@ separator = "•"
# Compatibility: https://caniuse.com/link-icon-svg # Compatibility: https://caniuse.com/link-icon-svg
# favicon_emoji = "🌱" # favicon_emoji = "🌱"
# This header image is used for SEO. For example if you were to share an image via Messenger/Instagram/Twitter a preview picture is also presented # Path to the fallback image for social media cards (the image shown when sharing a link on WhatsApp, LinkedIn…).
# headerImage = "" # Read more: https://nikitahl.com/html-meta-tags-for-social-media
# Using an image representative of each post is recommended. You can do so by setting this variable in the [extra] section of a post's front matter.
# If a post doesn't have a social media card, the site's default, below, will be used.
# social_media_card_path = ""
menu = [ menu = [
{ name = "blog", url = "blog", trailing_slash = true }, { name = "blog", url = "blog", trailing_slash = true },