From 72d82a233f738f5e865d1a3157a0efc11bb41e88 Mon Sep 17 00:00:00 2001 From: Conengmo <33519926+Conengmo@users.noreply.github.com> Date: Thu, 17 Oct 2024 19:02:37 +0200 Subject: [PATCH 1/2] make switcher match gh-pages --- .github/workflows/deploy-docs.yml | 11 +++++++++- docs/_static/switcher.json | 7 ++----- docs/update_switcher.py | 34 ++++++++++++++++--------------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 2b0ee1232..cb653adbf 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -70,10 +70,19 @@ jobs: destination_dir: dev keep_files: false - - name: Publish to Github Pages on release + - name: Publish to Github Pages on release (versioned) if: ${{ github.event_name == 'release' }} uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: docs/_build/html/ destination_dir: ${{ github.ref_name }} + + - name: Publish to Github Pages on release (latest) + if: ${{ github.event_name == 'release' }} + uses: peaceiris/actions-gh-pages@v4 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: docs/_build/html/ + destination_dir: latest + keep_files: false diff --git a/docs/_static/switcher.json b/docs/_static/switcher.json index 6bb4279ba..b0578b873 100644 --- a/docs/_static/switcher.json +++ b/docs/_static/switcher.json @@ -4,12 +4,9 @@ "url": "https://python-visualization.github.io/folium/dev/" }, { + "name": "latest (v0.17.0)", "version": "latest", - "url": "https://python-visualization.github.io/folium/v0.17.0/" - }, - { - "version": "v0.17.0", - "url": "https://python-visualization.github.io/folium/v0.17.0/" + "url": "https://python-visualization.github.io/folium/latest/" }, { "version": "v0.16.0", diff --git a/docs/update_switcher.py b/docs/update_switcher.py index fabf9e76a..850547fa8 100644 --- a/docs/update_switcher.py +++ b/docs/update_switcher.py @@ -6,6 +6,7 @@ import argparse import json import os +import re def main(): @@ -21,31 +22,32 @@ def main(): with open(switcher_path) as f: switcher = json.load(f) - # Find index of 'latest' entry - latest_index = None + # first we get the version number of the previous version for i, version in enumerate(switcher): if version["version"] == "latest": latest_index = i + previous_version = re.search(r"latest \(([v.\d]+)\)", version["name"]).group(1) + if previous_version == args.version: + print(f"Version {args.version} already is the latest version. Exiting.") + return + + # now replace the name of this one with the new version + switcher[i]["name"] = f"latest ({args.version})" break - if latest_index is None: + else: raise ValueError("'latest' version not found in switcher.json") - # Add the new version to the list of versions (we always insert it after latest) - new_version = { - "version": args.version, - "url": f"https://python-visualization.github.io/folium/{args.version}/", - } - - # Update the latest version - switcher[latest_index]["url"] = new_version["url"] - - # Make sure version is unique - if any(version["version"] == args.version for version in switcher): + # Add the previous version to the list of versions (we always insert it after latest) + if any(version["version"] == previous_version for version in switcher): print( - f"Version {args.version} already exists in switcher.json. Not adding it again." + f"Previous version {previous_version} already exists in switcher.json. Not adding it again." ) else: - switcher.insert(latest_index + 1, new_version) + previous_version_entry = { + "version": previous_version, + "url": f"https://python-visualization.github.io/folium/{previous_version}/", + } + switcher.insert(latest_index + 1, previous_version_entry) # Write the updated switcher.json with open(switcher_path, "w") as f: From c592753bfdc4ec25379910ffe4d3d05f7351ac2e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 19 Oct 2024 19:54:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/update_switcher.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/update_switcher.py b/docs/update_switcher.py index 850547fa8..17b1c996a 100644 --- a/docs/update_switcher.py +++ b/docs/update_switcher.py @@ -26,7 +26,9 @@ def main(): for i, version in enumerate(switcher): if version["version"] == "latest": latest_index = i - previous_version = re.search(r"latest \(([v.\d]+)\)", version["name"]).group(1) + previous_version = re.search( + r"latest \(([v.\d]+)\)", version["name"] + ).group(1) if previous_version == args.version: print(f"Version {args.version} already is the latest version. Exiting.") return