diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 5bde04a76..e3a18ce1a 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -71,10 +71,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..17b1c996a 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,34 @@ 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: