Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved social metadata settings #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,11 @@ disqus = { enabled=false, short_name="" }
# generate Table of Contents for all articles
# Table of Contents can be generated for individual articles
# by adding `ToC = true` in [extra] section in frontmatter
# ToC = true
# ToC = true

# Twitter metadata
# the website used in the card footer
# twitter_site="@username_website"
# for the actual author of the page
# (it can be overwrited specifying a custom `twitter_user` in [extra] in frontmatter)
# twitter_user="@username_user"
4 changes: 4 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
{{ social::og_preview() }}
{%- endblock og_preview -%}

{%- block twitter_preview -%}
{{ social::twitter_preview() }}
{%- endblock twitter_preview -%}

{%- block fonts -%}
{{ head::fonts() }}
{%- endblock fonts -%}
Expand Down
40 changes: 38 additions & 2 deletions templates/macros/social.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,47 @@
<meta property="og:url" content="{{ current_url }}"/>
{%- endif -%}
<meta property="og:description" content="{{ social::og_description() }}"/>
{%- if config.extra.og_preview_img -%}

{%- if section -%}
{%- if config.extra.og_preview_img -%}
<meta property="og:image" content="{{ get_url(path=config.extra.og_preview_img) }}"/>
{%- endif -%}
{%- endif -%}

{%- elif page -%}
{%- if page.extra.og_image -%}
<meta property="og:image" content="{{ current_url ~ page.extra.og_image | trim }}"/>
{%- elif config.extra.og_preview_img -%}
<meta property="og:image" content="{{ get_url(path=config.extra.og_preview_img) }}"/>
{%- endif -%}
{%- endif -%}{# ./if section #}
{% endmacro og_preview %}

{% macro twitter_preview() %}
{%- if page -%}
{% if page.extra.og_image %}
<meta name="twitter:card" content="summary_large_image">
{% else %}
<meta name="twitter:card" content="summary">
{%- endif -%}
{% else %}
<meta name="twitter:card" content="summary">
{%- endif -%}

{% if config.extra.twitter_site -%}
<meta name="twitter:site" content="{{ config.extra.twitter_site }}">
{%- endif -%}

{% if page %}
{%- if page.extra.twitter_user -%}
<meta name="twitter:creator" content="{{ page.extra.twitter_user }}">
{%- elif config.extra.twitter_user -%}
<meta name="twitter:creator" content="{{ config.extra.twitter_user }}">
{%- endif -%}{# ./if page.extra.twitter_user #}
{%- elif config.extra.twitter_user %}
<meta name="twitter:creator" content="{{ config.extra.twitter_user }}">
{%- endif %}{# ./if page #}
{% endmacro twitter_preview %}

{% macro og_description() %}
{%- if section -%}
{%- if section.description -%}
Expand Down