From 61bdca2db45179cd0d1b4b885a4c4864e3ffa3c1 Mon Sep 17 00:00:00 2001 From: Filippo Date: Tue, 9 Apr 2024 16:57:06 +0200 Subject: [PATCH 01/47] feat(analytics): add Umami and Matomo tracking codes (#1658) --- README.md | 2 +- _config.yml | 6 ++++++ _includes/analytics/matomo.html | 14 ++++++++++++++ _includes/analytics/umami.html | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 _includes/analytics/matomo.html create mode 100644 _includes/analytics/umami.html diff --git a/README.md b/README.md index f084852eeee..5bcfcb7fed4 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ - Built-in Search - Atom Feeds - PWA -- Google Analytics / GoatCounter +- Web Analytics - SEO & Performance Optimization ## Documentation diff --git a/_config.yml b/_config.yml index 1076673d013..f64411d6102 100644 --- a/_config.yml +++ b/_config.yml @@ -62,6 +62,12 @@ analytics: id: # fill in your Google Analytics ID goatcounter: id: # fill in your GoatCounter ID + umami: + id: # fill in your Umami ID + domain: # fill in your Umami domain + matomo: + id: # fill in your Matomo ID + domain: # fill in your Matomo domain # Pageviews settings pageviews: diff --git a/_includes/analytics/matomo.html b/_includes/analytics/matomo.html new file mode 100644 index 00000000000..72b2c463cfa --- /dev/null +++ b/_includes/analytics/matomo.html @@ -0,0 +1,14 @@ + + + diff --git a/_includes/analytics/umami.html b/_includes/analytics/umami.html new file mode 100644 index 00000000000..bfcb1d09ff6 --- /dev/null +++ b/_includes/analytics/umami.html @@ -0,0 +1,6 @@ + + From 9f8aeaadbfef9967a9b0a9dd323d8bed46e14d9f Mon Sep 17 00:00:00 2001 From: Azamat Mambetov Date: Sat, 13 Apr 2024 00:34:48 +0400 Subject: [PATCH 02/47] refactor!: rename media-url file and related parameters (#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` --- _config.yml | 6 +++--- _includes/embed/audio.html | 2 +- _includes/embed/video.html | 4 ++-- _includes/head.html | 4 ++-- _includes/{img-url.html => media-url.html} | 16 ++++++++-------- _includes/refactor-content.html | 2 +- _includes/sidebar.html | 2 +- _layouts/home.html | 2 +- _posts/2019-08-08-write-a-new-post.md | 14 +++++++------- _posts/2019-08-09-getting-started.md | 2 +- assets/js/data/swconf.js | 4 ++-- tools/init | 2 +- tools/release | 2 +- 13 files changed, 31 insertions(+), 31 deletions(-) rename _includes/{img-url.html => media-url.html} (59%) diff --git a/_config.yml b/_config.yml index f64411d6102..6062ac6ea8f 100644 --- a/_config.yml +++ b/_config.yml @@ -86,12 +86,12 @@ pageviews: # theme_mode: # [light | dark] -# The CDN endpoint for images. +# The CDN endpoint for media resources. # Notice that once it is assigned, the CDN url -# will be added to all image (site avatar & posts' images) paths starting with '/' +# will be added to all media resources (site avatar, posts' images, audio and video files) 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" diff --git a/_includes/embed/audio.html b/_includes/embed/audio.html index d618890af2f..e2b897901e2 100644 --- a/_includes/embed/audio.html +++ b/_includes/embed/audio.html @@ -4,7 +4,7 @@ {% unless src contains '://' %} {%- capture src -%} - {% include img-url.html src=src %} + {% include media-url.html src=src %} {%- endcapture -%} {% endunless %} diff --git a/_includes/embed/video.html b/_includes/embed/video.html index 72ec4fbeb69..712a266a345 100644 --- a/_includes/embed/video.html +++ b/_includes/embed/video.html @@ -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 subpath=page.media_subpath %} {%- endcapture -%} {% endunless %} {% assign poster = 'poster="' | append: poster_url | append: '"' %} diff --git a/_includes/head.html b/_includes/head.html index 2848c866137..67c5390d4f4 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -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 subpath=page.media_subpath absolute=true %} {%- endcapture -%} {%- capture old_url -%}{{ src | absolute_url }}{%- endcapture -%} @@ -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 -%} diff --git a/_includes/img-url.html b/_includes/media-url.html similarity index 59% rename from _includes/img-url.html rename to _includes/media-url.html index bb4758c72d3..ea410750268 100644 --- a/_includes/img-url.html +++ b/_includes/media-url.html @@ -1,25 +1,25 @@ {%- comment -%} - Generate image final URL based on `site.img_cdn`, `page.img_path` + Generate media resource final URL based on `site.cdn`, `page.media_subpath` Arguments: - src - required, basic image path - img_path - optional, relative path of image + src - required, basic media resources path + subpath - optional, relative path of media resources absolute - optional, boolean, if true, generate absolute URL Return: - image URL + media resources URL {%- endcomment -%} {% assign url = include.src %} {%- if url -%} {% unless url contains ':' %} - {%- comment -%} Add page image path prefix {%- endcomment -%} - {% assign url = include.img_path | default: '' | append: '/' | append: url %} + {%- comment -%} Add media resources subpath prefix {%- endcomment -%} + {% assign url = include.subpath | 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: ':/', '://' %} diff --git a/_includes/refactor-content.html b/_includes/refactor-content.html index e4abcbc2a51..8d298cde6c0 100644 --- a/_includes/refactor-content.html +++ b/_includes/refactor-content.html @@ -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 subpath=page.media_subpath %} {%- endcapture -%} {% assign _path_prefix = _img_url | remove: _src %} diff --git a/_includes/sidebar.html b/_includes/sidebar.html index b8f92e37e9d..0b5560a33b0 100644 --- a/_includes/sidebar.html +++ b/_includes/sidebar.html @@ -5,7 +5,7 @@ {%- 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 -%} avatar {%- endif -%} diff --git a/_layouts/home.html b/_layouts/home.html index a9f5bd366a7..e44efe8f4cb 100644 --- a/_layouts/home.html +++ b/_layouts/home.html @@ -49,7 +49,7 @@ {% if post.image %} {% assign src = post.image.path | default: post.image %} {% unless src contains '//' %} - {% assign src = post.img_path | append: '/' | append: src | replace: '//', '/' %} + {% assign src = post.media_subpath | append: '/' | append: src | replace: '//', '/' %} {% endunless %} {% assign alt = post.image.alt | xml_escape | default: 'Preview Image' %} diff --git a/_posts/2019-08-08-write-a-new-post.md b/_posts/2019-08-08-write-a-new-post.md index 0a451fa8c42..090453be9dd 100644 --- a/_posts/2019-08-08-write-a-new-post.md +++ b/_posts/2019-08-08-write-a-new-post.md @@ -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 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: ```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 media resources (site avatar, posts' images, audio and video files) starting with `/`. For instance, when using images: @@ -270,13 +270,13 @@ The parsing result will automatically add the CDN prefix `https://cdn.com` befor ``` {: .nolineno } -### Image Path +### Media Subpath -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: +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: ```yml --- -img_path: /img/path/ +media_subpath: /img/path/ --- ``` @@ -308,7 +308,7 @@ image: --- ``` -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. +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. For simple use, you can also just use `image` to define the path. diff --git a/_posts/2019-08-09-getting-started.md b/_posts/2019-08-09-getting-started.md index 701824fa35e..6653c62d9f4 100644 --- a/_posts/2019-08-09-getting-started.md +++ b/_posts/2019-08-09-getting-started.md @@ -8,7 +8,7 @@ date: 2019-08-09 20:55:00 +0800 categories: [Blogging, Tutorial] tags: [getting started] pin: true -img_path: '/posts/20180809' +media_subpath: '/posts/20180809' --- ## Prerequisites diff --git a/assets/js/data/swconf.js b/assets/js/data/swconf.js index cc11f79c750..c02638fa5e1 100644 --- a/assets/js/data/swconf.js +++ b/assets/js/data/swconf.js @@ -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 -%} diff --git a/tools/init b/tools/init index 5baac5d829c..bf1ef85871e 100755 --- a/tools/init +++ b/tools/init @@ -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 diff --git a/tools/release b/tools/release index 9ca63dccce4..965828bd541 100755 --- a/tools/release +++ b/tools/release @@ -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 From 7d48d32c7b272c48f1ce76dc3dc7f6ebf09468b4 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:16:15 +0800 Subject: [PATCH 03/47] ci: avoid duplicate builds for PR commits --- .github/workflows/ci.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7b1f5a692a..e1d4670ab02 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,8 @@ name: "CI" on: push: - branches-ignore: - - "production" - - "docs" + branches: + - "master" paths-ignore: - ".github/**" - "!.github/workflows/ci.yml" @@ -12,8 +11,6 @@ on: - "README.md" - "LICENSE" pull_request: - paths: - - "**" jobs: build: From 44f552cbcee83d037de0e59496bf6bb19eea2691 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:34:32 +0800 Subject: [PATCH 04/47] feat(deps): move `MathJax` configuration to a separate file (#1670) Move `MathJax` configuration to file `assets/js/data/mathjax.js` will help add extensions. --- _includes/js-selector.html | 20 +------------------- _posts/2019-08-08-write-a-new-post.md | 10 +++++++++- assets/js/data/mathjax.js | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 assets/js/data/mathjax.js diff --git a/_includes/js-selector.html b/_includes/js-selector.html index 662e9a45f26..2e52c9622d5 100644 --- a/_includes/js-selector.html +++ b/_includes/js-selector.html @@ -72,25 +72,7 @@ {% if page.math %} - + {% endif %} diff --git a/_posts/2019-08-08-write-a-new-post.md b/_posts/2019-08-08-write-a-new-post.md index 090453be9dd..0492b02930b 100644 --- a/_posts/2019-08-08-write-a-new-post.md +++ b/_posts/2019-08-08-write-a-new-post.md @@ -109,7 +109,9 @@ comments: false ## Mathematics -For website performance reasons, the mathematical feature won't be loaded by default. But it can be enabled by: +We use [**MathJax**][mathjax] to generate mathematics. For website performance reasons, the mathematical feature won't be loaded by default. But it can be enabled by: + +[mathjax]: https://www.mathjax.org/ ```yaml --- @@ -154,6 +156,12 @@ Can be referenced as \eqref{eq:label_name}. 3. \$$ LaTeX_math_expression $$ ``` +> Starting with `v7.0.0`, configuration options for **MathJax** have been moved to file `assets/js/data/mathjax.js`{: .filepath }, and you can change the options as needed, such as adding [extensions][mathjax-exts]. +> If you are building the site via `chirpy-starter`, copy that file from the gem installation directory (check with command `bundle info --path jekyll-theme-chirpy`) to the same directory in your repository. +{: .prompt-tip } + +[mathjax-exts]: https://docs.mathjax.org/en/latest/input/tex/extensions/index.html + ## Mermaid [**Mermaid**](https://github.com/mermaid-js/mermaid) is a great diagram generation tool. To enable it on your post, add the following to the YAML block: diff --git a/assets/js/data/mathjax.js b/assets/js/data/mathjax.js new file mode 100644 index 00000000000..ca3d0de52c7 --- /dev/null +++ b/assets/js/data/mathjax.js @@ -0,0 +1,25 @@ +--- +layout: compress +# WARNING: Don't use '//' to comment out code, use '{% comment %}' and '{% endcomment %}' instead. +--- + +{%- comment -%} + See: +{%- endcomment -%} + +MathJax = { + tex: { + {%- comment -%} start/end delimiter pairs for in-line math {%- endcomment -%} + inlineMath: [ + ['$', '$'], + ['\\(', '\\)'] + ], + {%- comment -%} start/end delimiter pairs for display math {%- endcomment -%} + displayMath: [ + ['$$', '$$'], + ['\\[', '\\]'] + ], + {%- comment -%} equation numbering {%- endcomment -%} + tags: 'ams' + } +}; From 1914c786a0bdd00ac15db4de45709f31e20e6010 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:40:01 +0800 Subject: [PATCH 05/47] docs: add missing head to changelog --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bc86dbc73c2..8a686ab30d4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -17,6 +17,8 @@ All notable changes to this project will be documented in this file. See [standa ## [6.5.3](https://github.com/cotes2020/jekyll-theme-chirpy/compare/v6.5.2...v6.5.3) (2024-03-07) +### Changes + * replace `polyfill.io` with `cdnjs` hosted link ([#1598](https://github.com/cotes2020/jekyll-theme-chirpy/pull/1598)) ([75a3d73](https://github.com/cotes2020/jekyll-theme-chirpy/commit/75a3d7399b257256a09d602cbe01062fe1cdf68d)) ## [6.5.2](https://github.com/cotes2020/jekyll-theme-chirpy/compare/v6.5.1...v6.5.2) (2024-02-29) From 7808ee157c7714e88e3ae2b504ae8a2961a02ec6 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 14 Apr 2024 04:45:52 +0800 Subject: [PATCH 06/47] chore: move starter workflow into subfolder The `.hook` suffix does not make it easy to maintain code in the editor --- .../{pages-deploy.yml.hook => starter/pages-deploy.yml} | 0 tools/init | 7 +++---- 2 files changed, 3 insertions(+), 4 deletions(-) rename .github/workflows/{pages-deploy.yml.hook => starter/pages-deploy.yml} (100%) diff --git a/.github/workflows/pages-deploy.yml.hook b/.github/workflows/starter/pages-deploy.yml similarity index 100% rename from .github/workflows/pages-deploy.yml.hook rename to .github/workflows/starter/pages-deploy.yml diff --git a/tools/init b/tools/init index bf1ef85871e..dd15c697d85 100755 --- a/tools/init +++ b/tools/init @@ -87,10 +87,9 @@ init_files() { rm -rf .github else ## Change the files of `.github` - mv .github/workflows/$ACTIONS_WORKFLOW.hook . - rm -rf .github - mkdir -p .github/workflows - mv ./${ACTIONS_WORKFLOW}.hook .github/workflows/${ACTIONS_WORKFLOW} + mv .github/workflows/starter/$ACTIONS_WORKFLOW . + rm -rf .github && mkdir -p .github/workflows + mv ./$ACTIONS_WORKFLOW .github/workflows/${ACTIONS_WORKFLOW} ## Cleanup image settings in site config _sedi "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" _config.yml From 8c1be9f2f38606a82925585dc8ad2bc36df8e6d5 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:06:06 +0800 Subject: [PATCH 07/47] ci: fix checkout depth for commitlint --- .github/workflows/commitlint.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml index f8cb2d529f9..c9c48c33f97 100644 --- a/.github/workflows/commitlint.yml +++ b/.github/workflows/commitlint.yml @@ -6,6 +6,4 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: wagoid/commitlint-github-action@v6 From bf16d6039ad8e6f9698c45b924725368a1d9d79d Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Sun, 14 Apr 2024 05:15:27 +0800 Subject: [PATCH 08/47] ci(release): replace `standard-version` with `semantic-release` (#1666) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [`standard-version`](https://github.com/conventional-changelog/standard-version/) has been deprecated since May 2022, so it is necessary to stop using it for this project. [**`semantic-release`**](https://github.com/semantic-release/semantic-release) is available as a more capable alternative to help automate the release process: 1. Updating Node/Gem version numbers 2. Generating changelogs 3. Automating GitHub Releases 4. Building Chirpy-gem and pushing it to RubyGems.org 5. Create commits and tags on the `production` branch 6. Merge the `production` branch into the `master` branch > ⚠️ Note: Step _6_ may be canceled in CD environments due to merge conflicts, so we need to do this step manually in such cases. Whenever a commit is pushed to the release branch (`production`), all of the above release processes will be triggered. --- .github/workflows/cd.yml | 38 ++++++-- .github/workflows/publish.yml | 17 ++++ docs/CHANGELOG.md | 2 - package.json | 93 +++++++++++++++---- tools/release | 168 +++++++++++++++------------------- 5 files changed, 193 insertions(+), 125 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 2e239a45073..bd9d2945c87 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -1,17 +1,37 @@ name: CD + on: push: - tags: - - "v[0-9]+.[0-9]+.[0-9]+" branches: - - docs + - production + tags-ignore: + - "**" jobs: - launch: + release: + permissions: + contents: write + issues: write + pull-requests: write runs-on: ubuntu-latest steps: - - run: | - curl -X POST -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${{ secrets.GH_PAT }}" \ - https://api.github.com/repos/${{ secrets.BUILDER }}/dispatches \ - -d '{"event_type":"deploy", "client_payload":{"branch": "${{ github.ref_name }}"}}' + - uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + bundler-cache: true + + - uses: actions/setup-node@v4 + with: + node-version: latest + + - run: npm install + - run: npx semantic-release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }} + + publish: + needs: release + uses: ./.github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000..20e46915167 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,17 @@ +name: Publish + +on: + push: + branches: + - docs + workflow_call: + +jobs: + launch: + runs-on: ubuntu-latest + steps: + - run: | + curl -X POST -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ secrets.GH_PAT }}" \ + https://api.github.com/repos/${{ secrets.BUILDER }}/dispatches \ + -d '{"event_type":"deploy", "client_payload":{"branch": "${{ github.ref_name }}"}}' diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8a686ab30d4..8f28580b180 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,7 +1,5 @@ # Changelog -All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. - ## [6.5.5](https://github.com/cotes2020/jekyll-theme-chirpy/compare/v6.5.4...v6.5.5) (2024-03-23) ### Bug Fixes diff --git a/package.json b/package.json index b023362daa0..79b81619d15 100644 --- a/package.json +++ b/package.json @@ -28,10 +28,15 @@ "@commitlint/config-conventional": "^19.1.0", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-terser": "^0.4.4", + "@semantic-release/changelog": "^6.0.3", + "@semantic-release/exec": "^6.0.3", + "@semantic-release/git": "^10.0.1", + "conventional-changelog-conventionalcommits": "^7.0.2", "husky": "^9.0.11", "rimraf": "^5.0.5", "rollup": "^4.13.2", "rollup-plugin-license": "^3.3.1", + "semantic-release": "^23.0.8", "stylelint": "^16.3.1", "stylelint-config-standard-scss": "^13.0.0" }, @@ -89,24 +94,76 @@ "media-feature-range-notation": "prefix" } }, - "standard-version": { - "skip": { - "commit": true, - "tag": true - }, - "types": [ - { - "type": "feat", - "section": "Features" - }, - { - "type": "fix", - "section": "Bug Fixes" - }, - { - "type": "perf", - "section": "Improvements" - } + "release": { + "branches": [ + "production" + ], + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "perf", + "section": "Improvements" + }, + { + "type": "refactor", + "section": "Changes", + "hidden": true + } + ] + } + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "docs/CHANGELOG.md", + "changelogTitle": "# Changelog" + } + ], + [ + "@semantic-release/npm", + { + "npmPublish": false + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "bash tools/release --prepare", + "publishCmd": "bash tools/release" + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "docs", + "package.json", + "*.gemspec" + ], + "message": "chore(release): ${nextRelease.version}\n\n${nextRelease.notes}" + } + ], + "@semantic-release/github" ] } } diff --git a/tools/release b/tools/release index 965828bd541..90b18232ea6 100755 --- a/tools/release +++ b/tools/release @@ -1,56 +1,47 @@ #!/usr/bin/env bash # -# Release a new version to the GitLab flow production branch. -# -# For a new major/minor version, bump version on the main branch, and then merge into the production branch. -# -# For a patch version, bump the version number on the patch branch, then merge that branch into the main branch -# and production branch. -# -# -# Usage: run on the default, release or the patch branch -# # Requires: Git, NPM and RubyGems set -eu -opt_pre=false # preview mode option - -working_branch="$(git branch --show-current)" +opt_pre=false # option for bump gem version +opt_pkg=false # option for building gem package -DEFAULT_BRANCH="$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')" - -PROD_BRANCH="production" +MAIN_BRANCH="master" +RELEASE_BRANCH="production" GEM_SPEC="jekyll-theme-chirpy.gemspec" -NODE_CONFIG="package.json" -CHANGE_LOG="docs/CHANGELOG.md" +NODE_SPEC="package.json" +CHANGELOG="docs/CHANGELOG.md" +CONFIG="_config.yml" JS_DIST="assets/js/dist" -BACKUP_PATH="$(mktemp -d)" FILES=( "$GEM_SPEC" - "$NODE_CONFIG" + "$NODE_SPEC" + "$CHANGELOG" + "$CONFIG" ) TOOLS=( "git" "npm" - "standard-version" "gem" ) help() { - echo "A tool to release new version Chirpy gem" + echo -e "A tool to release new version Chirpy gem.\nThis tool will:" + echo " 1. Build a new gem and publish it to RubyGems.org" + echo " 2. Merge the release branch into the default branch" echo echo "Usage:" - echo - echo " bash ./tools/release [options]" + echo " bash ./tools/release [options]" echo echo "Options:" - echo " -p, --preview Enable preview mode, only package, and will not modify the branches" - echo " -h, --help Print this information." + echo " --prepare Preparation for release" + echo " -p, --package Build a gem package only, for local packaging in case of auto-publishing failure" + echo " -h, --help Display this help message" } _check_cli() { @@ -70,11 +61,9 @@ _check_git() { exit 1 fi - $opt_pre || ( - if [[ $working_branch != "$DEFAULT_BRANCH" && - $working_branch != hotfix/* && - $working_branch != "$PROD_BRANCH" ]]; then - echo "> Abort: Please run on the default, release or patch branch." + $opt_pkg || ( + if [[ "$(git branch --show-current)" != "$RELEASE_BRANCH" ]]; then + echo "> Abort: Please run the tool in the '$RELEASE_BRANCH' branch." exit 1 fi ) @@ -103,108 +92,95 @@ check() { _check_node_packages } -# Auto-generate a new version number to the file 'package.json' -bump_node() { - bump="standard-version -i $CHANGE_LOG" - - if $opt_pre; then - bump="$bump -p rc" - fi - - eval "$bump" +## Bump new version to gem-spec file +_bump_version() { + _version="$(grep '"version":' "$NODE_SPEC" | sed 's/.*: "//;s/".*//')" + sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$_version/" "$GEM_SPEC" + echo "> Bump gem version to $_version" +} - # Change heading of Patch version to heading level 2 (a bug from `standard-version`) - sed -i "s/^### \[/## \[/g" "$CHANGE_LOG" +_improve_changelog() { # Replace multiple empty lines with a single empty line - sed -i "/^$/N;/^\n$/D" "$CHANGE_LOG" + sed -i '/^$/N;/^\n$/D' "$CHANGELOG" + # Escape left angle brackets of HTML tag in the changelog as they break the markdown structure. e.g., '
' + sed -i -E 's/\s(<[a-z])/ \\\1/g' "$CHANGELOG" } -## Bump new version to gem config file -bump_gem() { - _ver="$1" - - if $opt_pre; then - _ver="${1/-/.}" - fi - - sed -i "s/[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+/$_ver/" "$GEM_SPEC" -} - -# Creates a new tag on the production branch with the given version number. -# Also commits the changes and merges the production branch into the default branch. -branch() { - _version="$1" # X.Y.Z - - git add . - git commit -m "chore(release): $_version" - - # Create a new tag on production branch - echo -e "> Create tag v$_version\n" - git tag "v$_version" - - git checkout "$DEFAULT_BRANCH" - git merge --no-ff --no-edit "$PROD_BRANCH" - - if [[ $working_branch == hotfix/* ]]; then - # delete the patch branch - git branch -D "$working_branch" - fi +prepare() { + _bump_version + _improve_changelog } ## Build a Gem package build_gem() { - git checkout "$PROD_BRANCH" + if $opt_pkg; then + BACKUP_PATH="$(mktemp -d)" + cp "$JS_DIST"/* "$BACKUP_PATH" + fi # Remove unnecessary theme settings - sed -i "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" _config.yml + sed -i "s/^cdn:.*/cdn:/;s/^avatar:.*/avatar:/" $CONFIG rm -f ./*.gem npm run build git add "$JS_DIST" -f # add JS distribution files to gem gem build "$GEM_SPEC" - cp "$JS_DIST"/* "$BACKUP_PATH" - # Resume the settings + # resume the settings git reset git checkout . - # restore the dist files for future development - mkdir -p "$JS_DIST" && cp "$BACKUP_PATH"/* "$JS_DIST" - - # back to the default branch - git checkout "$DEFAULT_BRANCH" + if $opt_pkg; then + # restore the dist files for future development + mkdir -p "$JS_DIST" && cp "$BACKUP_PATH"/* "$JS_DIST" + rm -rf "$BACKUP_PATH" + fi } -main() { - check +# Push the gem to RubyGems.org (using $GEM_HOST_API_KEY) +push_gem() { + gem push ./*.gem +} - if [[ $opt_pre = false && $working_branch != "$PROD_BRANCH" ]]; then - git checkout "$PROD_BRANCH" - git merge --no-ff --no-edit "$working_branch" - fi +## Merge the release branch into the default branch +merge() { + git fetch origin "$MAIN_BRANCH" + git checkout -b "$MAIN_BRANCH" origin/"$MAIN_BRANCH" - bump_node + git merge --no-ff --no-edit "$RELEASE_BRANCH" || ( + git merge --abort + echo -e "\n> Conflict detected. Aborting merge.\n" + exit 0 + ) - _version="$(grep '"version":' "$NODE_CONFIG" | sed 's/.*: "//;s/".*//')" + git push origin "$MAIN_BRANCH" +} - bump_gem "$_version" +main() { + check - if [[ $opt_pre = false ]]; then - branch "$_version" + if $opt_pre; then + prepare + exit 0 fi - echo -e "> Build the gem package for v$_version\n" - build_gem + $opt_pkg && exit 0 + push_gem + merge } while (($#)); do opt="$1" case $opt in - -p | --preview) + --prepare) opt_pre=true shift ;; + -p | --package) + opt_pkg=true + shift + ;; -h | --help) help exit 0 From c85e9e239491dfafea83b68660807e6675edce44 Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 17 Apr 2024 06:00:36 +0800 Subject: [PATCH 09/47] ci: avoid trigger redundant workflows (#1682) CodeQL and Sytle Lint --- .github/workflows/codeql.yml | 1 + .github/workflows/style-lint.yml | 10 +++------- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index b09590d4830..06feb7fd69a 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -2,6 +2,7 @@ name: "CodeQL" on: push: + branches: ["master"] paths: ["_javascript/**/*.js"] pull_request: paths: ["_javascript/**/*.js"] diff --git a/.github/workflows/style-lint.yml b/.github/workflows/style-lint.yml index f7aa54db344..e095978d05a 100644 --- a/.github/workflows/style-lint.yml +++ b/.github/workflows/style-lint.yml @@ -2,14 +2,10 @@ name: "Style Lint" on: push: - branches-ignore: - - "production" - - "docs" - paths: - - "_sass/**/*.scss" + branches: ["master"] + paths: ["_sass/**/*.scss"] pull_request: - paths: - - "_sass/**/*.scss" + paths: ["_sass/**/*.scss"] jobs: stylelint: From fe7afa379f0af0ca98a207f85bdc0fa98575b1ad Mon Sep 17 00:00:00 2001 From: Cotes Chung <11371340+cotes2020@users.noreply.github.com> Date: Wed, 17 Apr 2024 06:10:01 +0800 Subject: [PATCH 10/47] perf: replace jQuery with Vanilla JS (#1681) Also replaced `magnific-popup` with `GLightbox` --- _data/origin/basic.yml | 9 +- _data/origin/cors.yml | 9 +- _includes/comments/disqus.html | 4 +- _includes/comments/giscus.html | 3 +- _includes/comments/utterances.html | 3 +- _includes/head.html | 4 +- _includes/js-selector.html | 11 +- _includes/mermaid.html | 50 +++---- _includes/sidebar.html | 2 +- _includes/topbar.html | 2 +- _javascript/modules/components/back-to-top.js | 15 +- .../modules/components/category-collapse.js | 49 ++++--- _javascript/modules/components/clipboard.js | 123 +++++++++-------- _javascript/modules/components/img-loading.js | 36 +++-- _javascript/modules/components/img-popup.js | 17 +-- .../modules/components/locale-datetime.js | 42 +++--- .../modules/components/mode-watcher.js | 15 +- .../modules/components/search-display.js | 130 ++++++++---------- _javascript/modules/components/sidebar.js | 12 +- _sass/addon/commons.scss | 25 ++-- assets/js/pwa/app.js | 14 +- assets/lib | 2 +- 22 files changed, 273 insertions(+), 304 deletions(-) diff --git a/_data/origin/basic.yml b/_data/origin/basic.yml index ed99ea850a6..73822515027 100644 --- a/_data/origin/basic.yml +++ b/_data/origin/basic.yml @@ -4,9 +4,6 @@ webfonts: /assets/lib/fonts/main.css # Libraries -jquery: - js: /assets/lib/jquery/jquery.min.js - bootstrap: css: /assets/lib/bootstrap/bootstrap.min.css js: /assets/lib/bootstrap/bootstrap.bundle.min.js @@ -31,9 +28,9 @@ dayjs: relativeTime: /assets/lib/dayjs/plugin/relativeTime.min.js localizedFormat: /assets/lib/dayjs/plugin/localizedFormat.min.js -magnific-popup: - css: /assets/lib/magnific-popup/magnific-popup.css - js: /assets/lib/magnific-popup/jquery.magnific-popup.min.js +glightbox: + css: /assets/lib/glightbox/glightbox.min.css + js: /assets/lib/glightbox/glightbox.min.js lazy-polyfill: css: /assets/lib/loading-attribute-polyfill/loading-attribute-polyfill.min.css diff --git a/_data/origin/cors.yml b/_data/origin/cors.yml index 614139f8e37..a10d31cc274 100644 --- a/_data/origin/cors.yml +++ b/_data/origin/cors.yml @@ -17,9 +17,6 @@ webfonts: https://fonts.googleapis.com/css2?family=Lato:wght@300;400&family=Sour # Libraries -jquery: - js: https://cdn.jsdelivr.net/npm/jquery@3.7.1/dist/jquery.min.js - bootstrap: css: https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css js: https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js @@ -44,9 +41,9 @@ dayjs: relativeTime: https://cdn.jsdelivr.net/npm/dayjs@1.11.10/plugin/relativeTime.min.js localizedFormat: https://cdn.jsdelivr.net/npm/dayjs@1.11.10/plugin/localizedFormat.min.js -magnific-popup: - css: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/magnific-popup.min.css - js: https://cdn.jsdelivr.net/npm/magnific-popup@1.1.0/dist/jquery.magnific-popup.min.js +glightbox: + css: https://cdn.jsdelivr.net/npm/glightbox@3.3.0/dist/css/glightbox.min.css + js: https://cdn.jsdelivr.net/npm/glightbox@3.3.0/dist/js/glightbox.min.js lazy-polyfill: css: https://cdn.jsdelivr.net/npm/loading-attribute-polyfill@2.1.1/dist/loading-attribute-polyfill.min.css diff --git a/_includes/comments/disqus.html b/_includes/comments/disqus.html index e59ed37dd2b..bef843acc35 100644 --- a/_includes/comments/disqus.html +++ b/_includes/comments/disqus.html @@ -28,7 +28,7 @@ { threshold: [0] } ); - disqus_observer.observe(document.querySelector('#disqus_thread')); + disqus_observer.observe(document.getElementById('disqus_thread')); /* Auto switch theme */ function reloadDisqus() { @@ -44,7 +44,7 @@ } } - if (document.querySelector('.mode-toggle')) { + if (document.getElementById('mode-toggle')) { window.addEventListener('message', reloadDisqus); } diff --git a/_includes/comments/giscus.html b/_includes/comments/giscus.html index 526aa22bcf1..f3b8a54b73c 100644 --- a/_includes/comments/giscus.html +++ b/_includes/comments/giscus.html @@ -2,7 +2,6 @@ diff --git a/_includes/sidebar.html b/_includes/sidebar.html index 0b5560a33b0..577cc13f814 100644 --- a/_includes/sidebar.html +++ b/_includes/sidebar.html @@ -44,7 +44,7 @@