From efe3a22f1fa002e3eb08bc1c756d045001a46ec2 Mon Sep 17 00:00:00 2001 From: Dean Attali <daattali@gmail.com> Date: Sat, 22 Aug 2020 08:39:54 +0000 Subject: [PATCH] refactor head tag to use variables --- _includes/head.html | 131 +++++++++++++++++++++----------------------- _layouts/base.html | 18 +++--- 2 files changed, 71 insertions(+), 78 deletions(-) diff --git a/_includes/head.html b/_includes/head.html index 6c29ce5..6f172e0 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -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 %} diff --git a/_layouts/base.html b/_layouts/base.html index bf7b5b4..59e6cd1 100644 --- a/_layouts/base.html +++ b/_layouts/base.html @@ -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>