Skip to content

Commit

Permalink
fix depth in nav
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Feb 19, 2024
1 parent b113431 commit 1d0a11e
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions website/scripts/mkdocs_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@ def read_config(file_path: str):
return yaml.load(f)


def nav_config(config):
_nav_config = []

def add_nav_entry(_title, _content):
if type(_content) == str:
_nav_config.append(_title)
else:
for _entry in _content:
for title, content in _entry.items():
add_nav_entry(title, content)

add_nav_entry(None, config["nav"])

return _nav_config


def create_translation_source(config_path, source_path):
config = read_config(config_path)

nav_config = []
for _entry in config["nav"]:
nav_config.append({v: k for k, v in _entry.items()})

tx_cfg = {"nav": nav_config}
tx_cfg = {"nav": nav_config(config)}

try:
tx_cfg["theme"] = {"palette": []}
Expand All @@ -43,11 +55,7 @@ def create_translation_source(config_path, source_path):

def update_config(config_path, source_path, source_language):
config = read_config(config_path)

nav_config = {}
for _entry in config["nav"]:
for title, page in _entry.items():
nav_config[page] = title
_nav_config = nav_config(config)

found = False
for plugin in config["plugins"]:
Expand All @@ -66,11 +74,13 @@ def update_config(config_path, source_path, source_language):
yaml = YAML()
tx = yaml.load(f)

for nav_entry in tx["nav"]:
for page, title in nav_entry.items():
source_language_tile = nav_config[page]
if title:
lang["nav_translations"][source_language_tile] = title
assert len(_nav_config) == len(tx["nav"])

lang["nav_translations"] = {}
for i in range(len(tx["nav"])):
lang["nav_translations"][_nav_config[i]] = (
tx["nav"][i] or _nav_config[i]
)

try:
lang["palette"] = copy.deepcopy(config["theme"]["palette"])
Expand Down

0 comments on commit 1d0a11e

Please sign in to comment.