From 7e7b9019744e96c2435d00dd0039f1d215954584 Mon Sep 17 00:00:00 2001 From: iBug Date: Sun, 5 May 2024 05:52:08 +0800 Subject: [PATCH] Add Rake task `:version` For updating all hard-coded version numbers from `package.json` --- README.md | 16 ++++++++-------- Rakefile | 25 ++++++++++++++++++++++++- docs/_config.yml | 1 - docs/_data/theme.yml | 3 +++ docs/_docs/01-quick-start-guide.md | 2 +- docs/_docs/04-upgrading.md | 4 ++-- 6 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 docs/_data/theme.yml diff --git a/README.md b/README.md index 9d10bd02..3514ce34 100644 --- a/README.md +++ b/README.md @@ -126,17 +126,12 @@ To install: **Looking for an example?** Use the [Minimal Mistakes remote theme starter](https://github.com/mmistakes/mm-github-pages-starter/generate) for the quickest method of getting a GitHub Pages hosted site up and running. Generate a new repository from the starter, replace sample content with your own, and configure as needed. diff --git a/Rakefile b/Rakefile index e5ef99da..65f5039c 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ require "shellwords" require "time" require "yaml" -task :default => [:copyright, :changelog, :js] +task :default => %i[copyright changelog js version] package_json = JSON.parse(File.read("package.json")) @@ -106,6 +106,7 @@ file "docs/_docs/18-history.md" => "CHANGELOG.md" do |t| f.puts "" f.puts "" f.puts "{% raw %}" + # Remove H1 changelog = File.read(t.prerequisites.first).gsub(/^# [^\n]*$/m, "").strip f.write changelog f.puts "" @@ -179,3 +180,25 @@ task :watch_js do rescue ThreadError end end + +task :version => ["docs/_data/theme.yml", "README.md", "docs/_pages/home.md"] + +file "docs/_data/theme.yml" => "package.json" do |t| + theme = { "version" => package_json["version"] } + File.open(t.name, "w") do |f| + f.puts "# for use with in-page templates" + f.puts theme.to_yaml + end +end + +file "README.md" => "package.json" do |t| + content = File.read(t.name) + content = content.gsub(/(mmistakes\/minimal-mistakes@)[\d.]+/, '\1' + package_json["version"]) + File.write(t.name, content) +end + +file "docs/_pages/home.md" => "package.json" do |t| + content = File.read(t.name) + content = content.gsub(/(\breleases\/tag\/|Latest release v)[\d.]+/, '\1' + package_json["version"]) + File.write(t.name, content) +end diff --git a/docs/_config.yml b/docs/_config.yml index 41e3d4a0..84684df8 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -6,7 +6,6 @@ # `jekyll serve`. If you change this file, please restart the server process. remote_theme : "mmistakes/minimal-mistakes@master" -theme_version : "4.25.1" # for use with in-page templates minimal_mistakes_skin : "default" # "air", "aqua", "contrast", "dark", "dirt", "neon", "mint", "plum", "sunrise" diff --git a/docs/_data/theme.yml b/docs/_data/theme.yml new file mode 100644 index 00000000..23054832 --- /dev/null +++ b/docs/_data/theme.yml @@ -0,0 +1,3 @@ +# for use with in-page templates +--- +version: 4.25.1 diff --git a/docs/_docs/01-quick-start-guide.md b/docs/_docs/01-quick-start-guide.md index 24351f74..0691f1d4 100644 --- a/docs/_docs/01-quick-start-guide.md +++ b/docs/_docs/01-quick-start-guide.md @@ -78,7 +78,7 @@ To install as a remote theme: bundle ``` -4. Add `remote_theme: "mmistakes/minimal-mistakes@{{ site.theme_version }}"` to your `_config.yml` file. Remove any other `theme:` or `remote_theme:` entry. +4. Add `remote_theme: "mmistakes/minimal-mistakes@{{ site.data.theme.version }}"` to your `_config.yml` file. Remove any other `theme:` or `remote_theme:` entry. You may also optionally specify a branch, [tag](https://github.com/mmistakes/minimal-mistakes/tags), or commit to use by appending an @ and the Git ref (e.g., `mmistakes/minimal-mistakes@4.9.0` or `mmistakes/minimal-mistakes@bbf3cbc5fd64a3e1885f3f99eb90ba92af84063d`). This is useful when rolling back to older versions of the theme. If you don't specify a Git ref, the latest on `master` will be used. diff --git a/docs/_docs/04-upgrading.md b/docs/_docs/04-upgrading.md index b50a5fd6..0f81e036 100644 --- a/docs/_docs/04-upgrading.md +++ b/docs/_docs/04-upgrading.md @@ -23,7 +23,7 @@ Simply run `bundle update` if you're using Bundler (have a `Gemfile`) or `gem up When using Bundler you can downgrade or lock the theme to a specific release ([tag][tag]), branch, or commit. Instead of `gem "minimal-mistakes-jekyll"` you'd add the following to your `Gemfile`: ```ruby -gem "minimal-mistakes-jekyll", :git => "https://github.com/mmistakes/minimal-mistakes.git", :tag => "{{ site.theme_version }}" +gem "minimal-mistakes-jekyll", :git => "https://github.com/mmistakes/minimal-mistakes.git", :tag => "{{ site.data.theme.version }}" ``` [tag]: https://github.com/mmistakes/minimal-mistakes/tags @@ -32,7 +32,7 @@ For more information on [installing gems from Git repositories](https://bundler. ## Remote theme -When setting `remote_theme: "mmistakes/minimal-mistakes@{{ site.theme_version }}"` in your `_config.yml` you may also optionally specify a branch, [tag][tag], or commit to use by appending an @ and the Git ref. +When setting `remote_theme: "mmistakes/minimal-mistakes@{{ site.data.theme.version }}"` in your `_config.yml` you may also optionally specify a branch, [tag][tag], or commit to use by appending an @ and the Git ref. For example, you can roll back to release 4.8.1 with `mmistakes/minimal-mistakes@4.8.1` or a specific commit with `mmistakes/minimal-mistakes@bbf3cbc5fd64a3e1885f3f99eb90ba92af84063d`). For a complete list of theme versions consult the [releases page](https://github.com/mmistakes/minimal-mistakes/releases).