Skip to content

Commit 49641c1

Browse files
authored
Create switchers maps from arrays of pairs (#231)
1 parent eff0dd9 commit 49641c1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

build_docs.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -388,16 +388,16 @@ def setup_switchers(
388388
- Cross-link various languages in a language switcher
389389
- Cross-link various versions in a version switcher
390390
"""
391-
languages_map = dict(sorted((l.tag, l.name) for l in languages if l.in_prod))
392-
versions_map = {v.name: v.picker_label for v in reversed(versions)}
391+
language_pairs = sorted((l.tag, l.name) for l in languages if l.in_prod)
392+
version_pairs = [(v.name, v.picker_label) for v in reversed(versions)]
393393

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

397397
template = Template(switchers_template_file.read_text(encoding="UTF-8"))
398398
rendered_template = template.safe_substitute(
399-
LANGUAGES=json.dumps(languages_map),
400-
VERSIONS=json.dumps(versions_map),
399+
LANGUAGES=json.dumps(language_pairs),
400+
VERSIONS=json.dumps(version_pairs),
401401
)
402402
switchers_path.write_text(rendered_template, encoding="UTF-8")
403403

templates/switchers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ const _CURRENT_PREFIX = (() => {
1919
return window.location.pathname.split('/', _NUM_PREFIX_PARTS).join('/') + '/';
2020
})();
2121

22-
const _ALL_VERSIONS = new Map(Object.entries($VERSIONS));
23-
const _ALL_LANGUAGES = new Map(Object.entries($LANGUAGES));
22+
const _ALL_VERSIONS = new Map($VERSIONS);
23+
const _ALL_LANGUAGES = new Map($LANGUAGES);
2424

2525
/**
2626
* @param {Map<string, string>} versions

0 commit comments

Comments
 (0)