Skip to content

Instantly share code, notes, and snippets.

@illvart
Last active March 10, 2020 22:10
Show Gist options
  • Save illvart/23178d13b06809e5ec80b6c59b2f1f5c to your computer and use it in GitHub Desktop.
Save illvart/23178d13b06809e5ec80b6c59b2f1f5c to your computer and use it in GitHub Desktop.
My Eleventy project meta-seo.njk
{% if permalink == "/" %}
{% set canonicalUrl = metadata.canonicalUrl %}
{% else %}
{% set canonicalUrl = metadata.canonicalUrl + page.url %}
{% endif %}
<link rel="canonical" href="{{ canonicalUrl }}">
{# Social meta #}
{% if section == "articles" %}
<meta property="og:type" content="blog">
{% else %}
<meta property="og:type" content="website">
{% endif %}
<meta property="og:url" content="{{ canonicalUrl }}">
<meta property="og:title" content="{{ title }}">
<meta property="og:description" content="{{ description or metadata.description }}">
<meta property="og:site_name" itemprop="name" content="{{ metadata.title }}">
<meta property="og:locale" content="{{ metadata.options.lang }}">
<meta property="og:locale:alternate" content="{{ metadata.options.lang_alternative }}">
<meta property="og:image" content="{{ ogImage or metadata.ogImage }}">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
{# Twitter card #}
{% if section == "home" %}
<meta name="twitter:card" content="summary_large_image">
{% else %}
<meta name="twitter:card" content="summary">
{% endif %}
<meta name="twitter:site" content="{{ metadata.twitter.site }}">
<meta name="twitter:creator" content="{{ metadata.twitter.creator }}">
<meta name="twitter:url" content="{{ canonicalUrl }}">
<meta name="twitter:title" content="{{ title }}">
<meta name="twitter:description" content="{{ description or metadata.description }}">
<meta name="twitter:image" content="{{ ogImage or metadata.ogImage }}">
{# Showing only articles view #}
{% if section == "articles" %}
{# Article meta #}
<meta property="article:author" content="{{ metadata.author.social.facebook }}">
<meta property="article:published_time" content="{{ page.date | toISODate }}">
{# Not show if tag post & posts #}
{% if tags != "post" %}
{% for tag in tags %}
{%- if tag != "post" and tag != "posts" -%}
<meta property="article:tag" content="{{ tag }}">
{%- endif -%}
{% endfor %}
{% endif %}
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment