Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename img-url to media-url and site.img_cdn to site.cdn #1651

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ theme_mode: # [light | dark]
# will be added to all image (site avatar & posts' images) paths starting with '/'
#
# e.g. 'https://cdn.com'
img_cdn: "https://chirpy-img.netlify.app"
cdn: "https://chirpy-img.netlify.app"

# the avatar on sidebar, support local or CORS resources
avatar: "/commons/avatar.jpg"
Expand Down
2 changes: 1 addition & 1 deletion _includes/embed/audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% unless src contains '://' %}
{%- capture src -%}
{% include img-url.html src=src %}
{% include media-url.html src=src %}
{%- endcapture -%}
{% endunless %}

Expand Down
4 changes: 2 additions & 2 deletions _includes/embed/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

{% unless video_url contains '://' %}
{%- capture video_url -%}
{% include img-url.html src=video_url %}
{% include media-url.html src=video_url %}
{%- endcapture -%}
{% endunless %}

{% if poster_url %}
{% unless poster_url contains '://' %}
{%- capture poster_url -%}
{% include img-url.html src=poster_url img_path=page.img_path %}
{% include media-url.html src=poster_url img_path=page.img_path %}
{%- endcapture -%}
{% endunless %}
{% assign poster = 'poster="' | append: poster_url | append: '"' %}
Expand Down
4 changes: 2 additions & 2 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{% unless src contains '://' %}
{%- capture img_url -%}
{% include img-url.html src=src img_path=page.img_path absolute=true %}
{% include media-url.html src=src img_path=page.img_path absolute=true %}
{%- endcapture -%}

{%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%}
Expand All @@ -31,7 +31,7 @@

{% elsif site.social_preview_image %}
{%- capture img_url -%}
{% include img-url.html src=site.social_preview_image absolute=true %}
{% include media-url.html src=site.social_preview_image absolute=true %}
{%- endcapture -%}

{%- capture og_image -%}
Expand Down
6 changes: 3 additions & 3 deletions _includes/img-url.html → _includes/media-url.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- comment -%}
Generate image final URL based on `site.img_cdn`, `page.img_path`
Generate image final URL based on `site.cdn`, `page.img_path`

Arguments:
src - required, basic image path
Expand All @@ -18,8 +18,8 @@
{% assign url = include.img_path | default: '' | append: '/' | append: url %}

{%- comment -%} Prepend CND URL {%- endcomment -%}
{% if site.img_cdn %}
{% assign url = site.img_cdn | append: '/' | append: url %}
{% if site.cdn %}
{% assign url = site.cdn | append: '/' | append: url %}
{% endif %}

{% assign url = url | replace: '///', '/' | replace: '//', '/' | replace: ':/', '://' %}
Expand Down
2 changes: 1 addition & 1 deletion _includes/refactor-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{% assign _lazyload = true %}

{%- capture _img_url -%}
{% include img-url.html src=_src img_path=page.img_path %}
{% include media-url.html src=_src img_path=page.img_path %}
{%- endcapture -%}

{% assign _path_prefix = _img_url | remove: _src %}
Expand Down
2 changes: 1 addition & 1 deletion _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<a href="{{ '/' | relative_url }}" id="avatar" class="rounded-circle">
{%- if site.avatar != empty and site.avatar -%}
{%- capture avatar_url -%}
{% include img-url.html src=site.avatar %}
{% include media-url.html src=site.avatar %}
{%- endcapture -%}
<img src="{{- avatar_url -}}" width="112" height="112" alt="avatar" onerror="this.style.display='none'">
{%- endif -%}
Expand Down
6 changes: 3 additions & 3 deletions _posts/2019-08-08-write-a-new-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ The screenshots of the program window can be considered to show the shadow effec

### CDN URL

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:
If you host the images on the CDN, you can save the time of repeatedly writing the CDN URL by assigning the variable `cdn` of `_config.yml`{: .filepath} file:

```yaml
img_cdn: https://cdn.com
cdn: https://cdn.com
```
{: file='_config.yml' .nolineno}

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 `/`.
Once `cdn` is assigned, the CDN URL will be added to the path of all images (images of site avatar and posts) starting with `/`.

For instance, when using images:

Expand Down
4 changes: 2 additions & 2 deletions assets/js/data/swconf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const swconf = {

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

{%- unless site.assets.self_host.enabled -%}
Expand Down
2 changes: 1 addition & 1 deletion tools/init
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ init_files() {
mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW}

## Cleanup image settings in site config
_sedi "s/^img_cdn:.*/img_cdn:/;s/^avatar:.*/avatar:/" _config.yml
_sedi "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" _config.yml
fi

# remove the other files
Expand Down
2 changes: 1 addition & 1 deletion tools/release
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ build_gem() {
git checkout "$PROD_BRANCH"

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

npm run build
Expand Down