Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create switchers maps from arrays of pairs #231

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,16 @@ def setup_switchers(
- Cross-link various languages in a language switcher
- Cross-link various versions in a version switcher
"""
languages_map = dict(sorted((l.tag, l.name) for l in languages if l.in_prod))
versions_map = {v.name: v.picker_label for v in reversed(versions)}
language_pairs = sorted((l.tag, l.name) for l in languages if l.in_prod)
version_pairs = [(v.name, v.picker_label) for v in reversed(versions)]

switchers_template_file = HERE / "templates" / "switchers.js"
switchers_path = html_root / "_static" / "switchers.js"

template = Template(switchers_template_file.read_text(encoding="UTF-8"))
rendered_template = template.safe_substitute(
LANGUAGES=json.dumps(languages_map),
VERSIONS=json.dumps(versions_map),
LANGUAGES=json.dumps(language_pairs),
VERSIONS=json.dumps(version_pairs),
)
switchers_path.write_text(rendered_template, encoding="UTF-8")

Expand Down
4 changes: 2 additions & 2 deletions templates/switchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const _CURRENT_PREFIX = (() => {
return window.location.pathname.split('/', _NUM_PREFIX_PARTS).join('/') + '/';
})();

const _ALL_VERSIONS = new Map(Object.entries($VERSIONS));
const _ALL_LANGUAGES = new Map(Object.entries($LANGUAGES));
const _ALL_VERSIONS = new Map($VERSIONS);
const _ALL_LANGUAGES = new Map($LANGUAGES);

/**
* @param {Map<string, string>} versions
Expand Down