Skip to content

Commit 9f8aeaa

Browse files
MrMurdock11cotes2020
authored andcommitted
refactor!: rename media-url file and related parameters (cotes2020#1651)
- Changed variable `img_cdn` to `cdn` in site configuration file. - Changed the variable defining the relative path of the image in the post from `img_url` to `media_subpath`
1 parent 61bdca2 commit 9f8aeaa

13 files changed

+31
-31
lines changed

_config.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ pageviews:
8686
#
8787
theme_mode: # [light | dark]
8888

89-
# The CDN endpoint for images.
89+
# The CDN endpoint for media resources.
9090
# Notice that once it is assigned, the CDN url
91-
# will be added to all image (site avatar & posts' images) paths starting with '/'
91+
# will be added to all media resources (site avatar, posts' images, audio and video files) paths starting with '/'
9292
#
9393
# e.g. 'https://cdn.com'
94-
img_cdn: "https://chirpy-img.netlify.app"
94+
cdn: "https://chirpy-img.netlify.app"
9595

9696
# the avatar on sidebar, support local or CORS resources
9797
avatar: "/commons/avatar.jpg"

_includes/embed/audio.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{% unless src contains '://' %}
66
{%- capture src -%}
7-
{% include img-url.html src=src %}
7+
{% include media-url.html src=src %}
88
{%- endcapture -%}
99
{% endunless %}
1010

_includes/embed/video.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
{% unless video_url contains '://' %}
77
{%- capture video_url -%}
8-
{% include img-url.html src=video_url %}
8+
{% include media-url.html src=video_url %}
99
{%- endcapture -%}
1010
{% endunless %}
1111

1212
{% if poster_url %}
1313
{% unless poster_url contains '://' %}
1414
{%- capture poster_url -%}
15-
{% include img-url.html src=poster_url img_path=page.img_path %}
15+
{% include media-url.html src=poster_url subpath=page.media_subpath %}
1616
{%- endcapture -%}
1717
{% endunless %}
1818
{% assign poster = 'poster="' | append: poster_url | append: '"' %}

_includes/head.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
{% unless src contains '://' %}
2222
{%- capture img_url -%}
23-
{% include img-url.html src=src img_path=page.img_path absolute=true %}
23+
{% include media-url.html src=src subpath=page.media_subpath absolute=true %}
2424
{%- endcapture -%}
2525

2626
{%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%}
@@ -31,7 +31,7 @@
3131

3232
{% elsif site.social_preview_image %}
3333
{%- capture img_url -%}
34-
{% include img-url.html src=site.social_preview_image absolute=true %}
34+
{% include media-url.html src=site.social_preview_image absolute=true %}
3535
{%- endcapture -%}
3636

3737
{%- capture og_image -%}

_includes/img-url.html _includes/media-url.html

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{%- comment -%}
2-
Generate image final URL based on `site.img_cdn`, `page.img_path`
2+
Generate media resource final URL based on `site.cdn`, `page.media_subpath`
33

44
Arguments:
5-
src - required, basic image path
6-
img_path - optional, relative path of image
5+
src - required, basic media resources path
6+
subpath - optional, relative path of media resources
77
absolute - optional, boolean, if true, generate absolute URL
88

99
Return:
10-
image URL
10+
media resources URL
1111
{%- endcomment -%}
1212

1313
{% assign url = include.src %}
1414

1515
{%- if url -%}
1616
{% unless url contains ':' %}
17-
{%- comment -%} Add page image path prefix {%- endcomment -%}
18-
{% assign url = include.img_path | default: '' | append: '/' | append: url %}
17+
{%- comment -%} Add media resources subpath prefix {%- endcomment -%}
18+
{% assign url = include.subpath | default: '' | append: '/' | append: url %}
1919

2020
{%- comment -%} Prepend CND URL {%- endcomment -%}
21-
{% if site.img_cdn %}
22-
{% assign url = site.img_cdn | append: '/' | append: url %}
21+
{% if site.cdn %}
22+
{% assign url = site.cdn | append: '/' | append: url %}
2323
{% endif %}
2424

2525
{% assign url = url | replace: '///', '/' | replace: '//', '/' | replace: ':/', '://' %}

_includes/refactor-content.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
{% assign _lazyload = true %}
9898

9999
{%- capture _img_url -%}
100-
{% include img-url.html src=_src img_path=page.img_path %}
100+
{% include media-url.html src=_src subpath=page.media_subpath %}
101101
{%- endcapture -%}
102102

103103
{% assign _path_prefix = _img_url | remove: _src %}

_includes/sidebar.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<a href="{{ '/' | relative_url }}" id="avatar" class="rounded-circle">
66
{%- if site.avatar != empty and site.avatar -%}
77
{%- capture avatar_url -%}
8-
{% include img-url.html src=site.avatar %}
8+
{% include media-url.html src=site.avatar %}
99
{%- endcapture -%}
1010
<img src="{{- avatar_url -}}" width="112" height="112" alt="avatar" onerror="this.style.display='none'">
1111
{%- endif -%}

_layouts/home.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{% if post.image %}
5050
{% assign src = post.image.path | default: post.image %}
5151
{% unless src contains '//' %}
52-
{% assign src = post.img_path | append: '/' | append: src | replace: '//', '/' %}
52+
{% assign src = post.media_subpath | append: '/' | append: src | replace: '//', '/' %}
5353
{% endunless %}
5454

5555
{% assign alt = post.image.alt | xml_escape | default: 'Preview Image' %}

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,14 @@ The screenshots of the program window can be considered to show the shadow effec
247247

248248
### CDN URL
249249

250-
If you host the images on the CDN, you can save the time of repeatedly writing the CDN URL by assigning the variable `img_cdn` of `_config.yml`{: .filepath} file:
250+
If you host the media resources on the CDN, you can save the time of repeatedly writing the CDN URL by assigning the variable `cdn` of `_config.yml`{: .filepath} file:
251251

252252
```yaml
253-
img_cdn: https://cdn.com
253+
cdn: https://cdn.com
254254
```
255255
{: file='_config.yml' .nolineno}
256256
257-
Once `img_cdn` is assigned, the CDN URL will be added to the path of all images (images of site avatar and posts) starting with `/`.
257+
Once `cdn` is assigned, the CDN URL will be added to the path of all media resources (site avatar, posts' images, audio and video files) starting with `/`.
258258

259259
For instance, when using images:
260260

@@ -270,13 +270,13 @@ The parsing result will automatically add the CDN prefix `https://cdn.com` befor
270270
```
271271
{: .nolineno }
272272

273-
### Image Path
273+
### Media Subpath
274274

275-
When a post contains many images, it will be a time-consuming task to repeatedly define the path of the images. To solve this, we can define this path in the YAML block of the post:
275+
When a post contains many images, it will be a time-consuming task to repeatedly define the path of the media resources. To solve this, we can define this path in the YAML block of the post:
276276

277277
```yml
278278
---
279-
img_path: /img/path/
279+
media_subpath: /img/path/
280280
---
281281
```
282282

@@ -308,7 +308,7 @@ image:
308308
---
309309
```
310310

311-
Note that 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.
311+
Note that the [`media_subpath`](#media-subpath) can also be passed to the preview image, that is, when it has been set, the attribute `path` only needs the image file name.
312312

313313
For simple use, you can also just use `image` to define the path.
314314

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ date: 2019-08-09 20:55:00 +0800
88
categories: [Blogging, Tutorial]
99
tags: [getting started]
1010
pin: true
11-
img_path: '/posts/20180809'
11+
media_subpath: '/posts/20180809'
1212
---
1313

1414
## Prerequisites

assets/js/data/swconf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const swconf = {
2424

2525
{%- comment -%} The request url with below domain will be cached. {%- endcomment -%}
2626
allowHosts: [
27-
{% if site.img_cdn and site.img_cdn contains '//' %}
28-
'{{ site.img_cdn | split: '//' | last | split: '/' | first }}',
27+
{% if site.cdn and site.cdn contains '//' %}
28+
'{{ site.cdn | split: '//' | last | split: '/' | first }}',
2929
{% endif %}
3030

3131
{%- unless site.assets.self_host.enabled -%}

tools/init

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ init_files() {
9393
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}
9494

9595
## Cleanup image settings in site config
96-
_sedi "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
96+
_sedi "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" _config.yml
9797
fi
9898

9999
# remove the other files

tools/release

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ build_gem() {
156156
git checkout "$PROD_BRANCH"
157157

158158
# Remove unnecessary theme settings
159-
sed -i "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
159+
sed -i "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" _config.yml
160160
rm -f ./*.gem
161161

162162
npm run build

0 commit comments

Comments
 (0)