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 6271a715a1
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
feat: initialize market app with browsing, product, and scraping code
Split from coop monolith. Includes:
- Market/browse/product blueprints
- Product sync API
- Suma scraping pipeline
- Templates for market, browse, and product views
- Dockerfile and CI workflow for independent deployment
2026-02-09 23:16:34 +00:00

25 lines
914 B
Python

from typing import Dict
from urllib.parse import urljoin
from 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