mirror of
https://github.com/rjNemo/fastapi
synced 2026-06-12 05:26:45 +00:00
🔧 Update docs script to make sure languages are always sorted (#1189)
This commit is contained in:
parent
4f88a5fddb
commit
06eaa32bf0
1 changed files with 8 additions and 4 deletions
|
|
@ -22,6 +22,10 @@ missing_translation_snippet = """
|
||||||
docs_path = Path("docs")
|
docs_path = Path("docs")
|
||||||
|
|
||||||
|
|
||||||
|
def get_lang_paths():
|
||||||
|
return sorted(docs_path.iterdir())
|
||||||
|
|
||||||
|
|
||||||
def lang_callback(lang: Optional[str]):
|
def lang_callback(lang: Optional[str]):
|
||||||
if lang is None:
|
if lang is None:
|
||||||
return
|
return
|
||||||
|
|
@ -34,7 +38,7 @@ def lang_callback(lang: Optional[str]):
|
||||||
|
|
||||||
def complete_existing_lang(incomplete: str):
|
def complete_existing_lang(incomplete: str):
|
||||||
lang_path: Path
|
lang_path: Path
|
||||||
for lang_path in docs_path.iterdir():
|
for lang_path in get_lang_paths():
|
||||||
if lang_path.is_dir() and lang_path.name.startswith(incomplete):
|
if lang_path.is_dir() and lang_path.name.startswith(incomplete):
|
||||||
yield lang_path.name
|
yield lang_path.name
|
||||||
|
|
||||||
|
|
@ -198,7 +202,7 @@ def build_all():
|
||||||
typer.echo(f"Building docs for: en")
|
typer.echo(f"Building docs for: en")
|
||||||
mkdocs.commands.build.build(mkdocs.config.load_config(site_dir=str(site_path)))
|
mkdocs.commands.build.build(mkdocs.config.load_config(site_dir=str(site_path)))
|
||||||
os.chdir(current_dir)
|
os.chdir(current_dir)
|
||||||
for lang in docs_path.iterdir():
|
for lang in get_lang_paths():
|
||||||
if lang == en_build_path or not lang.is_dir():
|
if lang == en_build_path or not lang.is_dir():
|
||||||
continue
|
continue
|
||||||
build_lang(lang.name)
|
build_lang(lang.name)
|
||||||
|
|
@ -220,7 +224,7 @@ def update_languages(
|
||||||
mkdocs.yml files (for all the languages).
|
mkdocs.yml files (for all the languages).
|
||||||
"""
|
"""
|
||||||
if lang is None:
|
if lang is None:
|
||||||
for lang_path in docs_path.iterdir():
|
for lang_path in get_lang_paths():
|
||||||
if lang_path.is_dir():
|
if lang_path.is_dir():
|
||||||
typer.echo(f"Updating {lang_path.name}")
|
typer.echo(f"Updating {lang_path.name}")
|
||||||
update_config(lang_path.name)
|
update_config(lang_path.name)
|
||||||
|
|
@ -278,7 +282,7 @@ def update_config(lang: str):
|
||||||
config_path = lang_path / mkdocs_name
|
config_path = lang_path / mkdocs_name
|
||||||
config: dict = mkdocs.utils.yaml_load(config_path.read_text(encoding="utf-8"))
|
config: dict = mkdocs.utils.yaml_load(config_path.read_text(encoding="utf-8"))
|
||||||
languages = [{"en": "/"}]
|
languages = [{"en": "/"}]
|
||||||
for lang in docs_path.iterdir():
|
for lang in get_lang_paths():
|
||||||
if lang.name == "en" or not lang.is_dir():
|
if lang.name == "en" or not lang.is_dir():
|
||||||
continue
|
continue
|
||||||
name = lang.name
|
name = lang.name
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue