Skip to content

Commit 72d82a2

Browse files
committed
make switcher match gh-pages
1 parent 5a7a173 commit 72d82a2

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

.github/workflows/deploy-docs.yml

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

73-
- name: Publish to Github Pages on release
73+
- name: Publish to Github Pages on release (versioned)
7474
if: ${{ github.event_name == 'release' }}
7575
uses: peaceiris/actions-gh-pages@v4
7676
with:
7777
github_token: ${{ secrets.GITHUB_TOKEN }}
7878
publish_dir: docs/_build/html/
7979
destination_dir: ${{ github.ref_name }}
80+
81+
- name: Publish to Github Pages on release (latest)
82+
if: ${{ github.event_name == 'release' }}
83+
uses: peaceiris/actions-gh-pages@v4
84+
with:
85+
github_token: ${{ secrets.GITHUB_TOKEN }}
86+
publish_dir: docs/_build/html/
87+
destination_dir: latest
88+
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: 18 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,32 @@ 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(r"latest \(([v.\d]+)\)", version["name"]).group(1)
30+
if previous_version == args.version:
31+
print(f"Version {args.version} already is the latest version. Exiting.")
32+
return
33+
34+
# now replace the name of this one with the new version
35+
switcher[i]["name"] = f"latest ({args.version})"
2936
break
30-
if latest_index is None:
37+
else:
3138
raise ValueError("'latest' version not found in switcher.json")
3239

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):
40+
# Add the previous version to the list of versions (we always insert it after latest)
41+
if any(version["version"] == previous_version for version in switcher):
4442
print(
45-
f"Version {args.version} already exists in switcher.json. Not adding it again."
43+
f"Previous version {previous_version} already exists in switcher.json. Not adding it again."
4644
)
4745
else:
48-
switcher.insert(latest_index + 1, new_version)
46+
previous_version_entry = {
47+
"version": previous_version,
48+
"url": f"https://python-visualization.github.io/folium/{previous_version}/",
49+
}
50+
switcher.insert(latest_index + 1, previous_version_entry)
4951

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

0 commit comments

Comments
 (0)