Skip to content

Commit efe3a22

Browse files
committed
refactor head tag to use variables
1 parent a04d8bb commit efe3a22

File tree

2 files changed

+71
-78
lines changed

2 files changed

+71
-78
lines changed

_includes/head.html

Lines changed: 62 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
<meta name="author" content="{{ site.author }}">
99
{% endif %}
1010

11-
{% if page.description %}
12-
<meta name="description" content="{{ page.description }}">
13-
{% elsif page.subtitle %}
14-
<meta name="description" content="{{ page.subtitle }}">
15-
{% elsif site.description %}
16-
<meta name="description" content="{{ site.description }}">
17-
{% endif %}
11+
{%- capture description -%}
12+
{%- if page.description -%}
13+
{{ page.description }}
14+
{%- elsif page.subtitle -%}
15+
{{ page.subtitle }}
16+
{%- else -%}
17+
{{ site.description }}
18+
{%- endif -%}
19+
{%- endcapture -%}
20+
<meta name="description" content="{{ description }}">
1821

1922
{% if site.mobile-theme-col %}
2023
<meta name="theme-color" content="{{ site.mobile-theme-col }}">
@@ -42,25 +45,24 @@
4245
{% endfor %}
4346
{% endif %}
4447

45-
{% if page.ext-css %}
46-
{% for css in page.ext-css %}
47-
{% include ext-css.html css=css %}
48-
{% endfor %}
49-
{% endif %}
50-
5148
{% if site.site-css %}
5249
{% for css in site.site-css %}
5350
<link rel="stylesheet" href="{{ css | relative_url }}">
5451
{% endfor %}
5552
{% endif %}
53+
54+
{% if page.ext-css %}
55+
{% for css in page.ext-css %}
56+
{% include ext-css.html css=css %}
57+
{% endfor %}
58+
{% endif %}
5659

5760
{% if page.css %}
5861
{% for css in page.css %}
5962
<link rel="stylesheet" href="{{ css | relative_url }}">
6063
{% endfor %}
6164
{% endif %}
6265

63-
<!-- Facebook OpenGraph tags -->
6466
{% if site.fb_app_id %}
6567
<meta property="fb:app_id" content="{{ site.fb_app_id }}">
6668
{% endif %}
@@ -69,22 +71,49 @@
6971
<meta property="og:site_name" content="{{ site.title }}">
7072
{% endif %}
7173

72-
{% if page.meta-title %}
73-
<meta property="og:title" content="{{ page.meta-title }}">
74-
{% elsif page.title %}
75-
<meta property="og:title" content="{{ page.title }}">
76-
{% elsif site.title %}
77-
<meta property="og:title" content="{{ site.title }}">
78-
{% endif %}
74+
{%- capture share-title -%}
75+
{%- if page.meta-title -%}
76+
{{ page.meta-title }}
77+
{%- elsif page.title -%}
78+
{{ page.title }}
79+
{%- else -%}
80+
{{ site.title }}
81+
{%- endif -%}
82+
{%- endcapture -%}
83+
84+
{%- capture share-description -%}
85+
{%- if page.meta-description -%}
86+
{{ page.meta-description }}
87+
{%- elsif page.subtitle -%}
88+
{{ page.subtitle }}
89+
{%- else -%}
90+
{{ {{ page.content | strip_html | xml_escape | truncatewords: 50 }} }}
91+
{%- endif -%}
92+
{%- endcapture -%}
93+
94+
{%- capture share-img -%}
95+
{%- if page.share-img -%}
96+
{{ page.share-img }}
97+
{%- elsif page.cover-img -%}
98+
{%- if page.cover-img.first -%}
99+
{{ page.cover-img[0].first.first }}
100+
{%- else -%}
101+
{{ page.cover-img }}
102+
{%- endif -%}
103+
{%- elsif page.thumbnail-img -%}
104+
{{ page.thumbnail-img }}
105+
{%- elsif site.avatar -%}
106+
{{ site.avatar }}
107+
{% endif %}
108+
{%- endcapture -%}
109+
{%- assign share-img=share-img | strip -%}
79110

80-
{% if page.meta-description %}
81-
<meta property="og:description" content="{{ page.meta-description }}">
82-
{% elsif page.subtitle %}
83-
<meta property="og:description" content="{{ page.subtitle }}">
84-
{% else %}
85-
<meta property="og:description" content="{{ page.content | strip_html | xml_escape | truncatewords: 50 }}">
86-
{% endif %}
111+
<meta property="og:title" content="{{ share-title }}">
112+
<meta property="og:description" content="{{ share-description }}">
87113

114+
{% if share-img != "" %}
115+
<meta property="og:image" content="{{ share-img | absolute_url }}">
116+
{% endif %}
88117

89118
{% if page.id %}
90119
<meta property="og:type" content="article">
@@ -102,63 +131,27 @@
102131
<link rel="canonical" href="{{ page.url | absolute_url | strip_index }}">
103132
{% endif %}
104133

105-
{%- capture shareimg -%}
106-
{% if page.share-img %}
107-
{{ page.share-img }}
108-
{% elsif page.cover-img %}
109-
{% if page.cover-img.first %}
110-
{{ page.cover-img[0].first.first }}
111-
{% else %}
112-
{{ page.cover-img }}
113-
{% endif %}
114-
{% elsif page.thumbnail-img %}
115-
{{ page.thumbnail-img }}
116-
{% elsif site.avatar %}
117-
{{ site.avatar }}
118-
{% endif %}
119-
{% endcapture %}
120-
{% assign shareimg=shareimg | strip %}
121-
122-
{% if shareimg != "" %}
123-
<meta property="og:image" content="{{ shareimg | absolute_url }}">
124-
{% endif %}
125-
126134

127-
<!-- Twitter summary cards -->
128-
{% if shareimg != "" and shareimg != site.avatar %}
135+
{% if share-img != "" and share-img != site.avatar %}
129136
<meta name="twitter:card" content="summary_large_image">
130137
{% else %}
131138
<meta name="twitter:card" content="summary">
132139
{% endif %}
133140
<meta name="twitter:site" content="@{{ site.social-network-links.twitter }}">
134141
<meta name="twitter:creator" content="@{{ site.social-network-links.twitter }}">
135142

136-
{% if page.meta-title %}
137-
<meta name="twitter:title" content="{{ page.meta-title }}">
138-
{% elsif page.title %}
139-
<meta name="twitter:title" content="{{ page.title }}">
140-
{% else %}
141-
<meta name="twitter:title" content="{{ site.title }}">
142-
{% endif %}
143-
144-
{% if page.meta-description %}
145-
<meta name="twitter:description" content="{{ page.meta-description }}">
146-
{% elsif page.subtitle %}
147-
<meta name="twitter:description" content="{{ page.subtitle }}">
148-
{% else %}
149-
<meta name="twitter:description" content="{{ page.content | strip_html | xml_escape | truncatewords: 50 }}">
150-
{% endif %}
143+
<meta property="twitter:title" content="{{ share-title }}">
144+
<meta property="twitter:description" content="{{ share-description }}">
151145

152-
{% if shareimg != "" %}
153-
<meta name="twitter:image" content="{{ shareimg | absolute_url }}">
146+
{% if share-img != "" %}
147+
<meta name="twitter:image" content="{{ share-img | absolute_url }}">
154148
{% endif %}
155149

156150
{% if site.matomo %}
157151
{% include matomo.html %}
158152
{% endif %}
159153

160154
{% if page.comments and site.staticman.repository and site.staticman.branch %}
161-
<!-- Staticman -->
162155
<link rel="stylesheet" href="{{ "/assets/css/staticman.css" | relative_url }}">
163156
{% endif %}
164157

_layouts/base.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@
2121

2222
<!DOCTYPE html>
2323
<html lang="{{ page.language | default: site.language | default: 'en' }}">
24-
<!-- Beautiful Jekyll | MIT license | Copyright Dean Attali 2020 -->
25-
{% include head.html %}
24+
<!-- Beautiful Jekyll | Copyright Dean Attali 2020 -->
25+
{% include head.html %}
2626

27-
<body>
27+
<body>
2828

29-
{% include gtm_body.html %}
29+
{% include gtm_body.html %}
3030

31-
{% include nav.html %}
31+
{% include nav.html %}
3232

33-
{{ content }}
33+
{{ content }}
3434

35-
{% include footer.html %}
35+
{% include footer.html %}
3636

37-
{% include footer-scripts.html %}
37+
{% include footer-scripts.html %}
3838

39-
</body>
39+
</body>
4040
</html>

0 commit comments

Comments
 (0)