This repository has been archived on 2026-02-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
market/scrape/build_snapshot/tools/rewrite_nav.py
giles 478636f799 feat: decouple market from shared_lib, add app-owned models
Phase 1-3 of decoupling:
- path_setup.py adds project root to sys.path
- Market-owned models in market/models/ (market, market_place)
- All imports updated: shared.infrastructure, shared.db, shared.browser, etc.
- MarketPlace uses container_type/container_id instead of post_id FK

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 12:46:32 +00:00

25 lines
921 B
Python

from typing import Dict
from urllib.parse import urljoin
from shared.config import config
def rewrite_nav(nav: Dict[str, Dict], nav_redirects:Dict[str, str]):
if nav_redirects:
for label, data in (nav.get("cats") or {}).items():
top_slug = (data or {}).get("slug")
if not top_slug:
continue
new_subs = []
for s in (data.get("subs") or []):
old_sub = (s.get("slug") or "").strip()
if not old_sub:
continue
old_path = f"/{top_slug}/{old_sub}"
canonical_path = nav_redirects.get(old_path, old_path)
parts = [x for x in canonical_path.split("/") if x]
top2, sub2 = parts[0], parts[1]
s["slug"] = sub2
s["href"] = urljoin(config()["base_url"], f"/{top2}/{sub2}")
new_subs.append(s)
data["subs"] = new_subs