mirror of https://github.com/astral-sh/ruff
Redirect from rule codes to rule pages in docs (#8636)
## Summary This adds redirects from, e.g., `https://docs.astral.sh/ruff/rules/F401` to `https://docs.astral.sh/ruff/rules/unused-import`, which are generated automatically when creating the documentation. Though we want to move towards human-readable names eventually, I think this is a nice and user-friendly change (and doesn't require any fancy infrastructure, since the redirects are handled via a plugin and added client-side). Closes #4710.
This commit is contained in:
parent
cbd9157bbf
commit
02946e7b0c
|
|
@ -2,3 +2,4 @@ PyYAML==6.0.1
|
||||||
black==23.10.0
|
black==23.10.0
|
||||||
mkdocs==1.5.0
|
mkdocs==1.5.0
|
||||||
git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@38c0b8187325c3bab386b666daf3518ac036f2f4
|
git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@38c0b8187325c3bab386b666daf3518ac036f2f4
|
||||||
|
mkdocs-redirects==1.2.1
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ PyYAML==6.0.1
|
||||||
black==23.10.0
|
black==23.10.0
|
||||||
mkdocs==1.5.0
|
mkdocs==1.5.0
|
||||||
mkdocs-material==9.1.18
|
mkdocs-material==9.1.18
|
||||||
|
mkdocs-redirects==1.2.1
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1 @@
|
||||||
INHERIT: mkdocs.generated.yml
|
INHERIT: mkdocs.generated.yml
|
||||||
plugins:
|
|
||||||
- search
|
|
||||||
- typeset
|
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ markdown_extensions:
|
||||||
alternate_style: true
|
alternate_style: true
|
||||||
plugins:
|
plugins:
|
||||||
- search
|
- search
|
||||||
|
- typeset
|
||||||
extra_css:
|
extra_css:
|
||||||
- stylesheets/extra.css
|
- stylesheets/extra.css
|
||||||
not_in_nav: |
|
not_in_nav: |
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
@ -138,9 +139,37 @@ def main() -> None:
|
||||||
|
|
||||||
f.write(clean_file_content(file_content, title))
|
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:
|
with Path("mkdocs.template.yml").open(encoding="utf8") as fp:
|
||||||
config = yaml.safe_load(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]
|
config["nav"] = [{section.title: section.filename} for section in SECTIONS]
|
||||||
|
|
||||||
with Path("mkdocs.generated.yml").open("w+") as fp:
|
with Path("mkdocs.generated.yml").open("w+") as fp:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue