diff --git a/contrib/build-docs b/contrib/build-docs index 68bc3cf71..ed503eb3a 100755 --- a/contrib/build-docs +++ b/contrib/build-docs @@ -105,6 +105,7 @@ main() { done done + python contrib/sort-mkdocs-versions rm -rf docs mv docs-main docs git checkout -- mkdocs.yml docs diff --git a/contrib/sort-mkdocs-versions b/contrib/sort-mkdocs-versions new file mode 100644 index 000000000..961dd8bf0 --- /dev/null +++ b/contrib/sort-mkdocs-versions @@ -0,0 +1,38 @@ +#!/usr/bin/env python +import json + + +def main(): + version_file = "tmp/docs-build/versions.json" + data = [] + with open(version_file) as f: + data = json.load(f) + + versions = [] + for info in data: + if info["title"] == "latest": + continue + versions.append(info["title"].removeprefix("v")) + + versions.sort(key=lambda x: list(map(int, x.split('.'))), reverse=True) + data = [ + { + "aliases": [], + "title": "latest", + "version": "docs", + } + ] + + for version in versions: + data.append({ + "aliases": [], + "title": f"v{version}", + "version": f"docs~v{version}", + }) + + with open(version_file, "w") as f: + json.dump(data, f, indent=4) + + +if __name__ == "__main__": + main()