Skip to content

Commit 0369da1

Browse files
make switcher match gh-pages (#2007)
* make switcher match gh-pages * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 9a69958 commit 0369da1

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,19 @@ jobs:
7171
destination_dir: dev
7272
keep_files: false
7373

74-
- name: Publish to Github Pages on release
74+
- name: Publish to Github Pages on release (versioned)
7575
if: ${{ github.event_name == 'release' }}
7676
uses: peaceiris/actions-gh-pages@v4
7777
with:
7878
github_token: ${{ secrets.GITHUB_TOKEN }}
7979
publish_dir: docs/_build/html/
8080
destination_dir: ${{ github.ref_name }}
81+
82+
- name: Publish to Github Pages on release (latest)
83+
if: ${{ github.event_name == 'release' }}
84+
uses: peaceiris/actions-gh-pages@v4
85+
with:
86+
github_token: ${{ secrets.GITHUB_TOKEN }}
87+
publish_dir: docs/_build/html/
88+
destination_dir: latest
89+
keep_files: false

docs/_static/switcher.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
"url": "https://python-visualization.github.io/folium/dev/"
55
},
66
{
7+
"name": "latest (v0.17.0)",
78
"version": "latest",
8-
"url": "https://python-visualization.github.io/folium/v0.17.0/"
9-
},
10-
{
11-
"version": "v0.17.0",
12-
"url": "https://python-visualization.github.io/folium/v0.17.0/"
9+
"url": "https://python-visualization.github.io/folium/latest/"
1310
},
1411
{
1512
"version": "v0.16.0",

docs/update_switcher.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import argparse
77
import json
88
import os
9+
import re
910

1011

1112
def main():
@@ -21,31 +22,34 @@ def main():
2122
with open(switcher_path) as f:
2223
switcher = json.load(f)
2324

24-
# Find index of 'latest' entry
25-
latest_index = None
25+
# first we get the version number of the previous version
2626
for i, version in enumerate(switcher):
2727
if version["version"] == "latest":
2828
latest_index = i
29+
previous_version = re.search(
30+
r"latest \(([v.\d]+)\)", version["name"]
31+
).group(1)
32+
if previous_version == args.version:
33+
print(f"Version {args.version} already is the latest version. Exiting.")
34+
return
35+
36+
# now replace the name of this one with the new version
37+
switcher[i]["name"] = f"latest ({args.version})"
2938
break
30-
if latest_index is None:
39+
else:
3140
raise ValueError("'latest' version not found in switcher.json")
3241

33-
# Add the new version to the list of versions (we always insert it after latest)
34-
new_version = {
35-
"version": args.version,
36-
"url": f"https://python-visualization.github.io/folium/{args.version}/",
37-
}
38-
39-
# Update the latest version
40-
switcher[latest_index]["url"] = new_version["url"]
41-
42-
# Make sure version is unique
43-
if any(version["version"] == args.version for version in switcher):
42+
# Add the previous version to the list of versions (we always insert it after latest)
43+
if any(version["version"] == previous_version for version in switcher):
4444
print(
45-
f"Version {args.version} already exists in switcher.json. Not adding it again."
45+
f"Previous version {previous_version} already exists in switcher.json. Not adding it again."
4646
)
4747
else:
48-
switcher.insert(latest_index + 1, new_version)
48+
previous_version_entry = {
49+
"version": previous_version,
50+
"url": f"https://python-visualization.github.io/folium/{previous_version}/",
51+
}
52+
switcher.insert(latest_index + 1, previous_version_entry)
4953

5054
# Write the updated switcher.json
5155
with open(switcher_path, "w") as f:

0 commit comments

Comments
 (0)