Skip to content

Commit 3e64400

Browse files
committed
Merge branch 'fix/seo-tag'
2 parents a60a456 + f581b43 commit 3e64400

File tree

9 files changed

+76
-29
lines changed

9 files changed

+76
-29
lines changed

_data/authors.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Template › https://github.com/jekyll/jekyll-seo-tag/blob/master/docs/advanced-usage.md#setting-author-url
2+
# -------------------------------------
3+
# {author_id}:
4+
# name: {full name}
5+
# twitter: {twitter_of_author}
6+
# url: {homepage_of_author}
7+
# -------------------------------------
8+
9+
cotes:
10+
name: Cotes Chung
11+
twitter: cotes2020
12+
url: https://github.com/cotes2020/
13+
14+
sille_bille:
15+
name: Dinesh Prasanth Moluguwan Krishnamoorthy
16+
twitter: dinesh_MKD
17+
url: https://github.com/SilleBille/

_includes/head.html

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,30 @@
2323

2424
{% endif %}
2525

26-
{% seo title=false %}
26+
{% capture seo_tags %}
27+
{% seo title=false %}
28+
{% endcapture %}
29+
30+
{% if site.img_cdn and seo_tags contains 'og:image' %}
31+
{% assign properties = 'og:image,twitter:image' | split: ',' %}
32+
33+
{% for prop in properties %}
34+
{% if site.img_cdn contains '//' %}
35+
<!-- `site.img_cdn` cross-origin URL -->
36+
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{% endcapture %}
37+
{% capture replacement %}<meta property="{{ prop }}" content="{{ site.img_cdn }}{% endcapture %}
38+
{% else %}
39+
<!-- `site.img_cdn` is a local file path -->
40+
{% capture target %}<meta property="{{ prop }}" content="{{ site.url }}{{ site.baseurl }}{% endcapture %}
41+
{% assign replacement = target | append: site.img_cdn %}
42+
{% endif %}
43+
44+
{% assign seo_tags = seo_tags | replace: target, replacement %}
45+
46+
{% endfor %}
47+
{% endif %}
48+
49+
{{ seo_tags }}
2750
2851
<title>
2952
{%- unless page.layout == "home" -%}

_includes/refactor-content.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@
9292

9393
<!-- Add CDN URL -->
9494
{% if site.img_cdn %}
95-
{% assign _src_prefix = site.img_cdn %}
95+
{% if site.img_cdn contains '//' %}
96+
{% assign _src_prefix = site.img_cdn %}
97+
{% else %}
98+
{% assign _src_prefix = site.img_cdn | relative_url %}
99+
{% endif %}
96100
{% else %}
97101
{% assign _src_prefix = site.baseurl %}
98102
{% endif %}

_layouts/post.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
{% include lang.html %}
1313

14-
{% if page.image.src %}
14+
{% if page.image.path %}
1515
{% capture bg %}
1616
{% unless page.image.no_bg %}{{ 'bg' }}{% endunless %}
1717
{% endcapture %}
18-
<img src="{{ page.image.src }}" class="preview-img {{ bg | strip }}"
18+
<img src="{{ page.image.path }}" class="preview-img {{ bg | strip }}"
1919
alt="{{ page.image.alt | default: "Preview Image" }}"
2020

2121
{% if page.image.width %}
@@ -37,11 +37,11 @@ <h1 data-toc-skip>{{ page.title }}</h1>
3737

3838
<!-- author -->
3939
<div>
40-
{% capture author_name %}{{ page.author.name | default: site.social.name }}{% endcapture %}
40+
{% capture author_name %}{{ site.data.authors[page.author].name | default: site.social.name }}{% endcapture %}
4141
{% assign author_link = nil %}
4242

43-
{% if page.author.link %}
44-
{% assign author_link = page.author.link %}
43+
{% if page.author %}
44+
{% assign author_link = site.data.authors[page.author].url %}
4545
{% elsif author_name == site.social.name %}
4646
{% assign author_link = site.social.links[0] %}
4747
{% endif %}

_posts/2019-08-08-text-and-typography.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
---
22
title: Text and Typography
3-
author:
4-
name: Cotes Chung
5-
link: https://github.com/cotes2020
3+
author: cotes
64
date: 2019-08-08 11:33:00 +0800
75
categories: [Blogging, Demo]
86
tags: [typography]
97
math: true
108
mermaid: true
119
image:
12-
src: /commons/devices-mockup.png
10+
path: /commons/devices-mockup.png
1311
width: 800
1412
height: 500
1513
---

_posts/2019-08-08-write-a-new-post.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
title: Writing a New Post
3-
author:
4-
name: Cotes Chung
5-
link: https://github.com/cotes2020
3+
author: cotes
64
date: 2019-08-08 14:10:00 +0800
75
categories: [Blogging, Tutorial]
86
tags: [writing]
@@ -50,14 +48,27 @@ tags: [bee]
5048

5149
The author information of the post usually does not need to be filled in the _Front Matter_ , they will be obtained from variables `social.name` and the first entry of `social.links` of the configuration file by default. But you can also override it as follows:
5250

51+
Add author information in `_data/authors.yml` (If your website doesn't have this file, don't hesitate to create one.)
52+
53+
```yaml
54+
<author_id>:
55+
name: <full name>
56+
twitter: <twitter_of_author>
57+
url: <homepage_of_author>
58+
```
59+
{: file="_data/authors.yml" }
60+
61+
And then set up the custom author in the post's YAML block:
62+
5363
```yaml
5464
---
55-
author:
56-
name: Full Name
57-
link: https://example.com
65+
author: <author_id>
5866
---
5967
```
6068

69+
> Another benefit of reading the author information from the file `_data/authors.yml`{: .filepath } is that the page will have the meta tag `twitter:creator`, which enriches the [Twitter Cards](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started#card-and-content-attribution) and is good for SEO.
70+
{: .prompt-info }
71+
6172
## Table of Contents
6273

6374
By default, the **T**able **o**f **C**ontents (TOC) is displayed on the right panel of the post. If you want to turn it off globally, go to `_config.yml`{: .filepath} and set the value of variable `toc` to `false`. If you want to turn off TOC for a specific post, add the following to the post's [Front Matter](https://jekyllrb.com/docs/front-matter/):
@@ -221,12 +232,12 @@ The output will be:
221232

222233
### Preview Image
223234

224-
If you want to add an image to the top of the post contents, specify the attribute `src`, `width`, `height`, and `alt` for the image:
235+
If you want to add an image to the top of the post contents, specify the attribute `path`, `width`, `height`, and `alt` for the image:
225236

226237
```yaml
227238
---
228239
image:
229-
src: /path/to/image/file
240+
path: /path/to/image/file
230241
width: 1000 # in pixels
231242
height: 400 # in pixels
232243
alt: image alternative text
@@ -235,7 +246,7 @@ image:
235246

236247
Except for `alt`, all other options are necessary, especially the `width` and `height`, which are related to user experience and web page loading performance. The above section "[Size](#size)" also mentions this.
237248

238-
Starting from _Chirpy v5.0.0_, the attributes `height` and `width` can be abbreviated: `height` → `h`, `width` → `w`. In addition, the [`img_path`](#image-path) can also be passed to the preview image, that is, when it has been set, the attribute `src` only needs the image file name.
249+
Starting from _Chirpy v5.0.0_, the attributes `height` and `width` can be abbreviated: `height` → `h`, `width` → `w`. In addition, the [`img_path`](#image-path) can also be passed to the preview image, that is, when it has been set, the attribute `path` only needs the image file name.
239250

240251
## Pinned Posts
241252

_posts/2019-08-09-getting-started.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
title: Getting Started
3-
author:
4-
name: Cotes Chung
5-
link: https://github.com/cotes2020
3+
author: cotes
64
date: 2019-08-09 20:55:00 +0800
75
categories: [Blogging, Tutorial]
86
tags: [getting started]

_posts/2019-08-11-customize-the-favicon.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
title: Customize the Favicon
3-
author:
4-
name: Cotes Chung
5-
link: https://github.com/cotes2020
3+
author: cotes
64
date: 2019-08-11 00:34:00 +0800
75
categories: [Blogging, Tutorial]
86
tags: [favicon]

_posts/2021-01-03-enable-google-pv.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
---
22
title: Enable Google Page Views
3-
author:
4-
name: Dinesh Prasanth Moluguwan Krishnamoorthy
5-
link: https://github.com/SilleBille
3+
author: sille_bille
64
date: 2021-01-03 18:32:00 -0500
75
categories: [Blogging, Tutorial]
86
tags: [google analytics, pageviews]

0 commit comments

Comments
 (0)