(block: dict, docs_root: Path)
| 143 | |
| 144 | |
| 145 | def _migrate_language_block(block: dict, docs_root: Path) -> dict: |
| 146 | locale = block["language"] |
| 147 | versions = block.get("versions", []) |
| 148 | if not versions: |
| 149 | return block |
| 150 | |
| 151 | # Detect already-migrated blocks: Edge present and at least one page |
| 152 | # path starts with ``edge/`` or ``v<digits>.<digits>``. |
| 153 | already_has_edge = any(v.get("version") == EDGE_VERSION for v in versions) |
| 154 | looks_prefixed = any( |
| 155 | isinstance(p, str) |
| 156 | and ( |
| 157 | p.startswith(f"{EDGE_PREFIX}/") or VERSION_SLUG_RE.match(p.split("/", 1)[0]) |
| 158 | ) |
| 159 | for v in versions |
| 160 | for p in _flatten_pages(v) |
| 161 | ) |
| 162 | if already_has_edge and looks_prefixed: |
| 163 | return block |
| 164 | |
| 165 | latest_entry = next( |
| 166 | (v for v in versions if v.get("version") == LATEST_DEFAULT_VERSION), |
| 167 | versions[0], |
| 168 | ) |
| 169 | |
| 170 | # First, prefix every versioned entry so the latest_entry below has the |
| 171 | # new ``v<X.Y.Z>/<locale>/...`` page paths. We need this BEFORE building |
| 172 | # Edge because Edge is cloned from the post-prefix latest_entry shape. |
| 173 | prefixed_entries: list[tuple[dict, dict | None]] = [] |
| 174 | for entry in versions: |
| 175 | if not _is_version_slug(entry.get("version", "")): |
| 176 | prefixed_entries.append((entry, entry)) |
| 177 | continue |
| 178 | prefixed = _prefix_version_entry(entry, locale) |
| 179 | # The historical docs.json listed pages that did not yet exist at older |
| 180 | # tags (the old nav-only versioning was lying about which pages were |
| 181 | # available per release). After prefixing, those paths point at files |
| 182 | # that don't exist in our frozen snapshots, so we drop them and let |
| 183 | # empty groups/tabs cascade away. |
| 184 | pruned = _prune_version_entry(prefixed, docs_root) |
| 185 | prefixed_entries.append((entry, pruned)) |
| 186 | |
| 187 | # Build Edge from the prefixed latest_entry so the clone has consistent |
| 188 | # shape; we'll rewrite its prefix to ``edge/``. |
| 189 | latest_prefixed = next( |
| 190 | (p for orig, p in prefixed_entries if orig is latest_entry and p), |
| 191 | None, |
| 192 | ) |
| 193 | if latest_prefixed is None: |
| 194 | # Latest version has no resolvable pages for this locale; skip Edge. |
| 195 | new_versions: list[dict] = [] |
| 196 | else: |
| 197 | edge_entry = _build_edge_entry(latest_prefixed, locale) |
| 198 | # Verify Edge resolves against docs/edge/<locale>/* on disk. |
| 199 | edge_pruned = _prune_version_entry(edge_entry, docs_root) |
| 200 | new_versions = [edge_pruned] if edge_pruned else [] |
| 201 | |
| 202 | for _orig, pruned in prefixed_entries: |
no test coverage detected