refactor head tag to use variables

This commit is contained in:
Dean Attali 2020-08-22 08:39:54 +00:00
parent a04d8bb1b6
commit efe3a22f1f
2 changed files with 71 additions and 78 deletions

View File

@ -8,13 +8,16 @@
<meta name="author" content="{{ site.author }}">
{% endif %}
{% if page.description %}
<meta name="description" content="{{ page.description }}">
{% elsif page.subtitle %}
<meta name="description" content="{{ page.subtitle }}">
{% elsif site.description %}
<meta name="description" content="{{ site.description }}">
{% endif %}
{%- capture description -%}
{%- if page.description -%}
{{ page.description }}
{%- elsif page.subtitle -%}
{{ page.subtitle }}
{%- else -%}
{{ site.description }}
{%- endif -%}
{%- endcapture -%}
<meta name="description" content="{{ description }}">
{% if site.mobile-theme-col %}
<meta name="theme-color" content="{{ site.mobile-theme-col }}">
@ -42,17 +45,17 @@
{% endfor %}
{% endif %}
{% if page.ext-css %}
{% for css in page.ext-css %}
{% include ext-css.html css=css %}
{% endfor %}
{% endif %}
{% if site.site-css %}
{% for css in site.site-css %}
<link rel="stylesheet" href="{{ css | relative_url }}">
{% endfor %}
{% endif %}
{% if page.ext-css %}
{% for css in page.ext-css %}
{% include ext-css.html css=css %}
{% endfor %}
{% endif %}
{% if page.css %}
{% for css in page.css %}
@ -60,7 +63,6 @@
{% endfor %}
{% endif %}
<!-- Facebook OpenGraph tags -->
{% if site.fb_app_id %}
<meta property="fb:app_id" content="{{ site.fb_app_id }}">
{% endif %}
@ -69,22 +71,49 @@
<meta property="og:site_name" content="{{ site.title }}">
{% endif %}
{% if page.meta-title %}
<meta property="og:title" content="{{ page.meta-title }}">
{% elsif page.title %}
<meta property="og:title" content="{{ page.title }}">
{% elsif site.title %}
<meta property="og:title" content="{{ site.title }}">
{% endif %}
{%- capture share-title -%}
{%- if page.meta-title -%}
{{ page.meta-title }}
{%- elsif page.title -%}
{{ page.title }}
{%- else -%}
{{ site.title }}
{%- endif -%}
{%- endcapture -%}
{% if page.meta-description %}
<meta property="og:description" content="{{ page.meta-description }}">
{% elsif page.subtitle %}
<meta property="og:description" content="{{ page.subtitle }}">
{% else %}
<meta property="og:description" content="{{ page.content | strip_html | xml_escape | truncatewords: 50 }}">
{% endif %}
{%- capture share-description -%}
{%- if page.meta-description -%}
{{ page.meta-description }}
{%- elsif page.subtitle -%}
{{ page.subtitle }}
{%- else -%}
{{ {{ page.content | strip_html | xml_escape | truncatewords: 50 }} }}
{%- endif -%}
{%- endcapture -%}
{%- capture share-img -%}
{%- if page.share-img -%}
{{ page.share-img }}
{%- elsif page.cover-img -%}
{%- if page.cover-img.first -%}
{{ page.cover-img[0].first.first }}
{%- else -%}
{{ page.cover-img }}
{%- endif -%}
{%- elsif page.thumbnail-img -%}
{{ page.thumbnail-img }}
{%- elsif site.avatar -%}
{{ site.avatar }}
{% endif %}
{%- endcapture -%}
{%- assign share-img=share-img | strip -%}
<meta property="og:title" content="{{ share-title }}">
<meta property="og:description" content="{{ share-description }}">
{% if share-img != "" %}
<meta property="og:image" content="{{ share-img | absolute_url }}">
{% endif %}
{% if page.id %}
<meta property="og:type" content="article">
@ -102,30 +131,8 @@
<link rel="canonical" href="{{ page.url | absolute_url | strip_index }}">
{% endif %}
{%- capture shareimg -%}
{% if page.share-img %}
{{ page.share-img }}
{% elsif page.cover-img %}
{% if page.cover-img.first %}
{{ page.cover-img[0].first.first }}
{% else %}
{{ page.cover-img }}
{% endif %}
{% elsif page.thumbnail-img %}
{{ page.thumbnail-img }}
{% elsif site.avatar %}
{{ site.avatar }}
{% endif %}
{% endcapture %}
{% assign shareimg=shareimg | strip %}
{% if shareimg != "" %}
<meta property="og:image" content="{{ shareimg | absolute_url }}">
{% endif %}
<!-- Twitter summary cards -->
{% if shareimg != "" and shareimg != site.avatar %}
{% if share-img != "" and share-img != site.avatar %}
<meta name="twitter:card" content="summary_large_image">
{% else %}
<meta name="twitter:card" content="summary">
@ -133,24 +140,11 @@
<meta name="twitter:site" content="@{{ site.social-network-links.twitter }}">
<meta name="twitter:creator" content="@{{ site.social-network-links.twitter }}">
{% if page.meta-title %}
<meta name="twitter:title" content="{{ page.meta-title }}">
{% elsif page.title %}
<meta name="twitter:title" content="{{ page.title }}">
{% else %}
<meta name="twitter:title" content="{{ site.title }}">
{% endif %}
<meta property="twitter:title" content="{{ share-title }}">
<meta property="twitter:description" content="{{ share-description }}">
{% if page.meta-description %}
<meta name="twitter:description" content="{{ page.meta-description }}">
{% elsif page.subtitle %}
<meta name="twitter:description" content="{{ page.subtitle }}">
{% else %}
<meta name="twitter:description" content="{{ page.content | strip_html | xml_escape | truncatewords: 50 }}">
{% endif %}
{% if shareimg != "" %}
<meta name="twitter:image" content="{{ shareimg | absolute_url }}">
{% if share-img != "" %}
<meta name="twitter:image" content="{{ share-img | absolute_url }}">
{% endif %}
{% if site.matomo %}
@ -158,7 +152,6 @@
{% endif %}
{% if page.comments and site.staticman.repository and site.staticman.branch %}
<!-- Staticman -->
<link rel="stylesheet" href="{{ "/assets/css/staticman.css" | relative_url }}">
{% endif %}

View File

@ -21,20 +21,20 @@ common-js:
<!DOCTYPE html>
<html lang="{{ page.language | default: site.language | default: 'en' }}">
<!-- Beautiful Jekyll | MIT license | Copyright Dean Attali 2020 -->
{% include head.html %}
<!-- Beautiful Jekyll | Copyright Dean Attali 2020 -->
{% include head.html %}
<body>
<body>
{% include gtm_body.html %}
{% include gtm_body.html %}
{% include nav.html %}
{% include nav.html %}
{{ content }}
{{ content }}
{% include footer.html %}
{% include footer.html %}
{% include footer-scripts.html %}
{% include footer-scripts.html %}
</body>
</body>
</html>