From 9d971201978e993a9af337d9cd5396a1ea225f00 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Thu, 23 Mar 2023 01:29:17 +0800 Subject: [PATCH 1/5] perf(assets): reduce HTTP requests to CDN --- _includes/comments/giscus.html | 72 ++++++++++++++++++--------------- _includes/head.html | 2 - _includes/js-selector.html | 38 +++++++++++------ _includes/jsdelivr-combine.html | 6 --- _includes/mermaid.html | 57 +++++++++++++------------- _includes/mode-toggle.html | 65 +++++++++++++++++++---------- _includes/search-loader.html | 49 +++++++++++----------- _includes/toc.html | 3 -- _layouts/default.html | 14 +++---- 9 files changed, 167 insertions(+), 139 deletions(-) diff --git a/_includes/comments/giscus.html b/_includes/comments/giscus.html index 29b848f..ed918a9 100644 --- a/_includes/comments/giscus.html +++ b/_includes/comments/giscus.html @@ -1,44 +1,54 @@ diff --git a/_includes/head.html b/_includes/head.html index 6407c9c..f767edb 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -108,8 +108,6 @@ - - {% unless site.theme_mode %} {% include mode-toggle.html %} {% endunless %} diff --git a/_includes/js-selector.html b/_includes/js-selector.html index 7d2224c..895ccef 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -1,27 +1,35 @@ + + +{% assign urls = site.data.assets[origin].jquery.js + | append: ',' + | append: site.data.assets[origin].bootstrap.js + | append: ',' + | append: site.data.assets[origin].search.js +%} + {% if page.layout == 'post' %} {% if site.google_analytics.pv.proxy_endpoint or site.google_analytics.pv.cache_path %} - + {% assign urls = urls | append: ',' | append: site.data.assets[origin].countup.js %} {% endif %} {% endif %} {% if page.layout == 'post' or page.layout == 'page' or page.layout == 'home' %} - {% assign _urls = site.data.assets[origin].lazysizes.js %} + {% assign urls = urls | append: ',' | append: site.data.assets[origin].lazysizes.js %} {% unless page.layout == 'home' %} - {% assign _urls = _urls + + {% assign urls = urls | append: ',' | append: site.data.assets[origin]['magnific-popup'].js | append: ',' | append: site.data.assets[origin].clipboard.js %} {% endunless %} - - {% include jsdelivr-combine.html urls=_urls %} {% endif %} {% if page.layout == 'home' @@ -32,7 +40,9 @@ %} {% assign locale = site.lang | split: '-' | first %} - {% assign _urls = site.data.assets[origin].dayjs.js.common + {% assign urls = urls + | append: ',' + | append: site.data.assets[origin].dayjs.js.common | append: ',' | append: site.data.assets[origin].dayjs.js.locale | replace: ':LOCALE', locale @@ -41,10 +51,18 @@ | append: ',' | append: site.data.assets[origin].dayjs.js.localizedFormat %} - - {% include jsdelivr-combine.html urls=_urls %} {% endif %} +{% if page.content contains ' {% endif %} - - - - {% if jekyll.environment == 'production' %} {% if site.pwa.enabled %} diff --git a/_includes/jsdelivr-combine.html b/_includes/jsdelivr-combine.html index 960eeb1..cffa699 100644 --- a/_includes/jsdelivr-combine.html +++ b/_includes/jsdelivr-combine.html @@ -5,7 +5,6 @@ {% assign domain = 'https://cdn.jsdelivr.net/' %} {% for url in urls %} - {% if url contains domain %} {% assign url_snippet = url | slice: domain.size, url.size %} @@ -16,15 +15,10 @@ {% endif %} {% elsif url contains '//' %} - - {% else %} - - {% endif %} - {% endfor %} {% if combined_urls %} diff --git a/_includes/mermaid.html b/_includes/mermaid.html index 2ec8029..967cfb4 100644 --- a/_includes/mermaid.html +++ b/_includes/mermaid.html @@ -1,59 +1,58 @@ - - - - - diff --git a/_includes/mode-toggle.html b/_includes/mode-toggle.html index ada0061..a347750 100644 --- a/_includes/mode-toggle.html +++ b/_includes/mode-toggle.html @@ -1,14 +1,22 @@ - + - diff --git a/_includes/toc.html b/_includes/toc.html index 6b18693..1eb3dcd 100644 --- a/_includes/toc.html +++ b/_includes/toc.html @@ -10,7 +10,4 @@
{{- site.data.locales[include.lang].panel.toc -}}
- - - {% endif %} diff --git a/_layouts/default.html b/_layouts/default.html index 2349852..755c59e 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -21,7 +21,6 @@ layout: compress {% include sidebar.html lang=lang %} - {% include topbar.html lang=lang %}
@@ -31,14 +30,9 @@ layout: compress {% include search-results.html lang=lang %}
- {% include footer.html lang=lang %} - {% if page.mermaid %} - {% include mermaid.html %} - {% endif %} -
@@ -72,8 +66,12 @@ layout: compress {% endif %} - {% include search-loader.html %} - {% include js-selector.html %} + + {% if page.mermaid %} + {% include mermaid.html %} + {% endif %} + + {% include search-loader.html %} From c283e7782fa9562d82d9855fd280a573fd58c75f Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Fri, 31 Mar 2023 06:41:51 +0800 Subject: [PATCH 2/5] refactor!: rename assets origin configuration files --- .../self_host.yml => origin/basic.yml} | 0 .../cross_origin.yml => origin/cors.yml} | 0 _includes/head.html | 15 ++++---- _includes/js-selector.html | 38 +++++++++---------- .../{assets-origin.html => origin-type.html} | 9 +++-- _layouts/default.html | 2 +- _layouts/page.html | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) rename _data/{assets/self_host.yml => origin/basic.yml} (100%) rename _data/{assets/cross_origin.yml => origin/cors.yml} (100%) rename _includes/{assets-origin.html => origin-type.html} (52%) diff --git a/_data/assets/self_host.yml b/_data/origin/basic.yml similarity index 100% rename from _data/assets/self_host.yml rename to _data/origin/basic.yml diff --git a/_data/assets/cross_origin.yml b/_data/origin/cors.yml similarity index 100% rename from _data/assets/cross_origin.yml rename to _data/origin/cors.yml diff --git a/_includes/head.html b/_includes/head.html index f767edb..0c85fe1 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -58,15 +58,15 @@ {% include favicons.html %} {% if site.resources.ignore_env != jekyll.environment and site.resources.self_hosted %} - + {% else %} - {% for cdn in site.data.assets[origin].cdns %} + {% for cdn in site.data.origin[type].cdns %} {% endfor %} - + {% endif %} @@ -90,20 +90,20 @@ {% endif %} - + - + {% if site.toc and page.toc %} - + {% endif %} {% if page.layout == 'page' or page.layout == 'post' %} - + {% endif %} @@ -113,5 +113,4 @@ {% endunless %} {% include metadata-hook.html %} - diff --git a/_includes/js-selector.html b/_includes/js-selector.html index 895ccef..177aaf2 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -2,11 +2,11 @@ -{% assign urls = site.data.assets[origin].jquery.js +{% assign urls = site.data.origin[type].jquery.js | append: ',' - | append: site.data.assets[origin].bootstrap.js + | append: site.data.origin[type].bootstrap.js | append: ',' - | append: site.data.assets[origin].search.js + | append: site.data.origin[type].search.js %} @@ -14,20 +14,20 @@ {% if page.layout == 'post' %} {% if site.google_analytics.pv.proxy_endpoint or site.google_analytics.pv.cache_path %} - {% assign urls = urls | append: ',' | append: site.data.assets[origin].countup.js %} + {% assign urls = urls | append: ',' | append: site.data.origin[type].countup.js %} {% endif %} {% endif %} {% if page.layout == 'post' or page.layout == 'page' or page.layout == 'home' %} - {% assign urls = urls | append: ',' | append: site.data.assets[origin].lazysizes.js %} + {% assign urls = urls | append: ',' | append: site.data.origin[type].lazysizes.js %} {% unless page.layout == 'home' %} {% assign urls = urls | append: ',' - | append: site.data.assets[origin]['magnific-popup'].js + | append: site.data.origin[type]['magnific-popup'].js | append: ',' - | append: site.data.assets[origin].clipboard.js + | append: site.data.origin[type].clipboard.js %} {% endunless %} {% endif %} @@ -42,37 +42,37 @@ {% assign urls = urls | append: ',' - | append: site.data.assets[origin].dayjs.js.common + | append: site.data.origin[type].dayjs.js.common | append: ',' - | append: site.data.assets[origin].dayjs.js.locale + | append: site.data.origin[type].dayjs.js.locale | replace: ':LOCALE', locale | append: ',' - | append: site.data.assets[origin].dayjs.js.relativeTime + | append: site.data.origin[type].dayjs.js.relativeTime | append: ',' - | append: site.data.assets[origin].dayjs.js.localizedFormat + | append: site.data.origin[type].dayjs.js.localizedFormat %} {% endif %} {% if page.content contains ' {% if page.math %} @@ -94,8 +94,8 @@ } }; - - + + {% endif %} {% if jekyll.environment == 'production' %} diff --git a/_includes/assets-origin.html b/_includes/origin-type.html similarity index 52% rename from _includes/assets-origin.html rename to _includes/origin-type.html index 841e252..7f72012 100644 --- a/_includes/assets-origin.html +++ b/_includes/origin-type.html @@ -1,12 +1,13 @@ -{% comment %} Site static assets origin {% endcomment %} -{% assign origin = 'cross_origin' %} +{% comment %} Site static assets origin type {% endcomment %} + +{% assign type = 'cors' %} {% if site.assets.self_host.enabled %} {% if site.assets.self_host.env %} {% if site.assets.self_host.env == jekyll.environment %} - {% assign origin = 'self_host' %} + {% assign type = 'basic' %} {% endif %} {% else %} - {% assign origin = 'self_host' %} + {% assign type = 'basic' %} {% endif %} {% endif %} diff --git a/_layouts/default.html b/_layouts/default.html index 755c59e..d6ff29c 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -5,7 +5,7 @@ layout: compress -{% include assets-origin.html %} +{% include origin-type.html %} {% include lang.html %} diff --git a/_layouts/page.html b/_layouts/page.html index 917a4f4..fc2c915 100644 --- a/_layouts/page.html +++ b/_layouts/page.html @@ -3,7 +3,7 @@ layout: default --- {% include lang.html %} -{% include assets-origin.html %} +{% include origin-type.html %}
From 1967de1f1da5d97b97aa5f829a40c2b37bf78ed5 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 9 Apr 2023 20:44:55 +0800 Subject: [PATCH 3/5] refactor(js): reduce function complexity --- .../modules/components/topbar-switcher.js | 54 ++++++++++--------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/_javascript/modules/components/topbar-switcher.js b/_javascript/modules/components/topbar-switcher.js index f3eebb7..1b0d025 100644 --- a/_javascript/modules/components/topbar-switcher.js +++ b/_javascript/modules/components/topbar-switcher.js @@ -6,7 +6,6 @@ import ScrollHelper from './utils/scroll-helper'; const $searchInput = $('#search-input'); const delta = ScrollHelper.getTopbarHeight(); -let didScroll; let lastScrollTop = 0; function hasScrolled() { @@ -60,34 +59,41 @@ function handleLandscape() { export function switchTopbar() { const orientation = screen.orientation; - if (orientation) { - orientation.onchange = () => { - const type = orientation.type; - if (type === 'landscape-primary' || type === 'landscape-secondary') { - handleLandscape(); - } - }; - } else { - // for the browsers that not support `window.screen.orientation` API - $(window).on('orientationchange', () => { - if ($(window).width() < $(window).height()) { - // before rotating, it is still in portrait mode. - handleLandscape(); - } - }); - } + let didScroll = false; - $(window).on('scroll', () => { - if (didScroll) { - return; + const handleOrientationChange = () => { + const type = orientation.type; + if (type === 'landscape-primary' || type === 'landscape-secondary') { + handleLandscape(); } - didScroll = true; - }); + }; - setInterval(() => { + const handleWindowChange = () => { + if ($(window).width() < $(window).height()) { + // before rotating, it is still in portrait mode. + handleLandscape(); + } + }; + + const handleScroll = () => { + didScroll = true; + }; + + const checkScroll = () => { if (didScroll) { hasScrolled(); didScroll = false; } - }, 250); + }; + + if (orientation) { + orientation.addEventListener('change', handleOrientationChange); + } else { + // for the browsers that not support `window.screen.orientation` API + $(window).on('orientationchange', handleWindowChange); + } + + $(window).on('scroll', handleScroll); + + setInterval(checkScroll, 250); } From ea6268d7a5035e9ef7e39544ed49432f828c043f Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 3 May 2023 01:48:57 +0800 Subject: [PATCH 4/5] chore(ci): upgrade commit-lint actions --- .github/workflows/commitlint.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index 1e05511..affd492 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -5,7 +5,7 @@ jobs: commitlint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - - uses: wagoid/commitlint-github-action@v4 + - uses: wagoid/commitlint-github-action@v5 From 25ec7649cd80b788ecfcc51e7c8a4bc9e8150069 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sat, 13 May 2023 05:45:18 +0800 Subject: [PATCH 5/5] chore(deps): upgrade the version of depdencies (#953, #994) Resolves #953, #994 --- _data/origin/cors.yml | 18 +++++++++--------- assets/lib | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/_data/origin/cors.yml b/_data/origin/cors.yml index 594e9dc..cf8f0ec 100644 --- a/_data/origin/cors.yml +++ b/_data/origin/cors.yml @@ -16,31 +16,31 @@ webfonts: https://fonts.googleapis.com/css2?family=Lato&family=Source+Sans+Pro:w # Libraries jquery: - js: https://cdn.jsdelivr.net/npm/jquery@3.6.1/dist/jquery.min.js + js: https://cdn.jsdelivr.net/npm/jquery@3.7.0/dist/jquery.min.js bootstrap: css: https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css js: https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js toc: - css: https://cdn.jsdelivr.net/npm/tocbot@4.20.1/dist/tocbot.min.css - js: https://cdn.jsdelivr.net/npm/tocbot@4.20.1/dist/tocbot.min.js + css: https://cdn.jsdelivr.net/npm/tocbot@4.21.0/dist/tocbot.min.css + js: https://cdn.jsdelivr.net/npm/tocbot@4.21.0/dist/tocbot.min.js fontawesome: - css: https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.2.1/css/all.min.css + css: https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css search: js: https://cdn.jsdelivr.net/npm/simple-jekyll-search@1.10.0/dest/simple-jekyll-search.min.js mermaid: - js: https://cdn.jsdelivr.net/npm/mermaid@9.2.2/dist/mermaid.min.js + js: https://cdn.jsdelivr.net/npm/mermaid@9.4.3/dist/mermaid.min.js dayjs: js: - common: https://cdn.jsdelivr.net/npm/dayjs@1.11.6/dayjs.min.js - locale: https://cdn.jsdelivr.net/npm/dayjs@1.11.6/locale/:LOCALE.min.js - relativeTime: https://cdn.jsdelivr.net/npm/dayjs@1.11.6/plugin/relativeTime.min.js - localizedFormat: https://cdn.jsdelivr.net/npm/dayjs@1.11.6/plugin/localizedFormat.min.js + common: https://cdn.jsdelivr.net/npm/dayjs@1.11.7/dayjs.min.js + locale: https://cdn.jsdelivr.net/npm/dayjs@1.11.7/locale/:LOCALE.min.js + relativeTime: https://cdn.jsdelivr.net/npm/dayjs@1.11.7/plugin/relativeTime.min.js + localizedFormat: https://cdn.jsdelivr.net/npm/dayjs@1.11.7/plugin/localizedFormat.min.js countup: js: https://cdn.jsdelivr.net/npm/countup.js@1.9.3/dist/countUp.min.js diff --git a/assets/lib b/assets/lib index 24ebdb7..5f28c7d 160000 --- a/assets/lib +++ b/assets/lib @@ -1 +1 @@ -Subproject commit 24ebdb708f3f5451df953cb5f9deb3ad4433404a +Subproject commit 5f28c7d5107a1c2e30381765194269680a3d0eae