diff --git a/.gitignore b/.gitignore index 6bed67465ad6341d9c73f3d94c641b0aa1398621..b803f4928c2c05654dc534d0a48ff70d9fbe15b7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ vale/styles/* !vale/styles/config/ !vale/styles/custom/ .DS_Store +wf_redirects.yaml .idea .venv diff --git a/docs/scripts/gen_wf_redirects.py b/docs/scripts/gen_wf_redirects.py new file mode 100644 index 0000000000000000000000000000000000000000..9e48581ccee60f54b2b085ac9b4255765af615c2 --- /dev/null +++ b/docs/scripts/gen_wf_redirects.py @@ -0,0 +1,38 @@ +"""Generate pages to forward workflow URLs. + +This will redirect `/workflow/workflow_name` to `reference/gso/workflow/module/workflow_name`. This is required since +URLs cannot be changed in the GUI. +""" + +from pathlib import Path + +import yaml + +root = Path(__file__).parent.parent.parent +src = root / "gso" +redirect_map = {} + +for path in sorted(src.rglob("*.py")): + module_path = path.relative_to(root).with_suffix("") + parts = tuple(module_path.parts) + + if parts[-1] == "__init__": + parts = parts[:-1] + elif parts[-1] == "__main__": + continue + + if len(parts) == 4 and "workflows" in parts: + redirect_map["workflow/" + parts[3] + "/index.md"] = "https://docs.gap.geant.org/reference/" + "/".join(parts) + +with open(root / "wf_redirects.yaml", 'w') as redirect_file: + file_content = { + "plugins": + [ + "search", + {"gen-files": {"scripts": ["docs/scripts/gen_ref_pages.py"]}}, + {"redirects": {"redirect_maps": redirect_map}}, + {"literate-nav": {"nav_file": "SUMMARY.md"}}, + "mkdocstrings", + ] + } + yaml.dump(file_content, redirect_file) diff --git a/mkdocs.yml b/mkdocs.yml index a90ca43fa8ce0cd430c86dcbf85e046731035a00..c6808360a62ca9bed8c3ce6ac78da20a79d5fcd2 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,3 +1,4 @@ +INHERIT: wf_redirects.yaml # General site_name: GÉANT Automation Platform site_url: https://docs.gap.geant.org/ @@ -44,15 +45,6 @@ theme: extra_css: - assets/stylesheets/extra.css -plugins: - - search - - gen-files: - scripts: - - docs/scripts/gen_ref_pages.py - - literate-nav: - nav_file: SUMMARY.md - - mkdocstrings - # Page tree nav: - Home: index.md