diff --git a/docs/requirements-insiders.txt b/docs/requirements-insiders.txt index 49c55012e5..e89b7e229a 100644 --- a/docs/requirements-insiders.txt +++ b/docs/requirements-insiders.txt @@ -2,3 +2,4 @@ PyYAML==6.0.1 black==23.10.0 mkdocs==1.5.0 git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@38c0b8187325c3bab386b666daf3518ac036f2f4 +mkdocs-redirects==1.2.1 diff --git a/docs/requirements.txt b/docs/requirements.txt index 06094f6076..b60a10740a 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,3 +2,4 @@ PyYAML==6.0.1 black==23.10.0 mkdocs==1.5.0 mkdocs-material==9.1.18 +mkdocs-redirects==1.2.1 diff --git a/mkdocs.insiders.yml b/mkdocs.insiders.yml index 7435eb6a01..1842e9ead2 100644 --- a/mkdocs.insiders.yml +++ b/mkdocs.insiders.yml @@ -1,4 +1 @@ INHERIT: mkdocs.generated.yml -plugins: - - search - - typeset diff --git a/mkdocs.template.yml b/mkdocs.template.yml index f3410e93d7..a34a8881ca 100644 --- a/mkdocs.template.yml +++ b/mkdocs.template.yml @@ -60,6 +60,7 @@ markdown_extensions: alternate_style: true plugins: - search + - typeset extra_css: - stylesheets/extra.css not_in_nav: | diff --git a/scripts/generate_mkdocs.py b/scripts/generate_mkdocs.py index c90126382d..1d12263135 100644 --- a/scripts/generate_mkdocs.py +++ b/scripts/generate_mkdocs.py @@ -2,6 +2,7 @@ from __future__ import annotations import argparse +import json import re import shutil import subprocess @@ -138,9 +139,37 @@ def main() -> None: f.write(clean_file_content(file_content, title)) - # Add the nav section to mkdocs.yml. with Path("mkdocs.template.yml").open(encoding="utf8") as fp: config = yaml.safe_load(fp) + + # Add the redirect section to mkdocs.yml. + rules = json.loads( + subprocess.check_output( + [ + "cargo", + "run", + "-p", + "ruff_cli", + "--", + "rule", + "--all", + "--output-format", + "json", + ], + ), + ) + config["plugins"].append( + { + "redirects": { + "redirect_maps": { + f'rules/{rule["code"]}.md': f'rules/{rule["name"]}.md' + for rule in rules + }, + }, + }, + ) + + # Add the nav section to mkdocs.yml. config["nav"] = [{section.title: section.filename} for section in SECTIONS] with Path("mkdocs.generated.yml").open("w+") as fp: