Skip to content

Commit c9d2f7f

Browse files
committed
refactor: the real patch
1 parent 8ae17bc commit c9d2f7f

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

_includes/head.html

+24-9
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,47 @@
44
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#1b1b1e">
55
<meta name="apple-mobile-web-app-capable" content="yes">
66
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
7-
<meta name="viewport" content="width=device-width, user-scalable=no initial-scale=1, shrink-to-fit=no, viewport-fit=cover">
7+
<meta
8+
name="viewport"
9+
content="width=device-width, user-scalable=no initial-scale=1, shrink-to-fit=no, viewport-fit=cover"
10+
>
811

912
{%- capture seo_tags -%}
1013
{% seo title=false %}
1114
{%- endcapture -%}
1215

13-
{% assign img_url = '' %}
16+
<!-- Setup Open Graph image -->
1417

1518
{% if page.image %}
1619
{% assign src = page.image.path | default: page.image %}
20+
1721
{% unless src contains '://' %}
1822
{%- capture img_url -%}
19-
{{ site.url }}{% include img-url.html src=src img_path=page.img_path %}
23+
{% include img-url.html src=src img_path=page.img_path absolute=true %}
2024
{%- endcapture -%}
25+
26+
{%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%}
27+
{%- capture new_url -%}{{ img_url }}{%- endcapture -%}
28+
29+
{% assign seo_tags = seo_tags | replace: old_url, new_url %}
2130
{% endunless %}
31+
2232
{% elsif site.social_preview_image %}
2333
{%- capture img_url -%}
24-
{{ site.url }}{% include img-url.html src=site.social_preview_image %}
34+
{% include img-url.html src=site.social_preview_image absolute=true %}
2535
{%- endcapture -%}
26-
{% endif %}
2736

28-
{% if img_url != '' %}
2937
{%- capture og_image -%}
3038
<meta property="og:image" content="{{ img_url }}" />
31-
<meta name="twitter:image" content="{{ img_url }}" />
3239
{%- endcapture -%}
3340

34-
{% assign old_meta_clip = '<meta name="twitter:card"' %}
35-
{% assign new_meta_clip = og_image | append: old_meta_clip %}
41+
{%- capture twitter_image -%}
42+
<meta property="twitter:card" content="summary_large_image" />
43+
<meta property="twitter:image" content="{{ img_url }}" />
44+
{%- endcapture -%}
45+
46+
{% assign old_meta_clip = '<meta name="twitter:card" content="summary" />' %}
47+
{% assign new_meta_clip = og_image | append: twitter_image %}
3648
{% assign seo_tags = seo_tags | replace: old_meta_clip, new_meta_clip %}
3749
{% endif %}
3850

@@ -58,18 +70,21 @@
5870

5971
{% if site.resources.ignore_env != jekyll.environment and site.resources.self_hosted %}
6072
<link href="{{ site.data.origin[type].webfonts | relative_url }}" rel="stylesheet">
73+
6174
{% else %}
6275
{% for cdn in site.data.origin[type].cdns %}
6376
<link rel="preconnect" href="{{ cdn.url }}" {{ cdn.args }}>
6477
<link rel="dns-prefetch" href="{{ cdn.url }}" {{ cdn.args }}>
6578
{% endfor %}
79+
6680
<link rel="stylesheet" href="{{ site.data.origin[type].webfonts | relative_url }}">
6781
{% endif %}
6882

6983
<!-- GA -->
7084
{% if jekyll.environment == 'production' and site.google_analytics.id != empty and site.google_analytics.id %}
7185
<link rel="preconnect" href="https://www.google-analytics.com" crossorigin="use-credentials">
7286
<link rel="dns-prefetch" href="https://www.google-analytics.com">
87+
7388
<link rel="preconnect" href="https://www.googletagmanager.com" crossorigin="anonymous">
7489
<link rel="dns-prefetch" href="https://www.googletagmanager.com">
7590
{% endif %}

_includes/img-url.html

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
Generate image final URL based on `site.img_cdn`, `page.img_path`
33

44
Arguments:
5-
src - basic image path, required
6-
img_path - relative path of image, optional
5+
src - required, basic image path
6+
img_path - optional, relative path of image
7+
absolute - optional, boolean, if true, generate absolute URL
78

89
Return:
910
image URL
@@ -14,7 +15,7 @@
1415
{%- if url -%}
1516
{% unless url contains ':' %}
1617
{%- comment -%} CND URL {%- endcomment -%}
17-
{% assign prefix = site.img_cdn | default: '' | relative_url %}
18+
{% assign prefix = site.img_cdn | default: '' %}
1819

1920
{%- comment -%} Add page image path prefix {%- endcomment -%}
2021
{% assign url = include.img_path | default: '' | append: '/' | append: url %}
@@ -26,6 +27,12 @@
2627
| replace: '//', '/'
2728
| replace: ':', ':/'
2829
%}
30+
31+
{% if include.absolute %}
32+
{% assign url = url | absolute_url %}
33+
{% else %}
34+
{% assign url = url | relative_url %}
35+
{% endif %}
2936
{% endunless %}
3037
{%- endif -%}
3138

0 commit comments

Comments
 (0)