diff --git a/scripts/patterns-reorg/deleted_entries.py b/scripts/patterns-reorg/deleted_entries.py new file mode 100644 index 00000000000..78a5616cabc --- /dev/null +++ b/scripts/patterns-reorg/deleted_entries.py @@ -0,0 +1,7 @@ +from models import DeletedPage + +DELETED_PAGES = ( + DeletedPage(old_slug="build/index", redirect_to="/map-problem-to-circuits"), + DeletedPage(old_slug="run/index", redirect_to="/execute-on-hardware"), + DeletedPage(old_slug="start/index", redirect_to=""), +) diff --git a/scripts/patterns-reorg/main.py b/scripts/patterns-reorg/main.py index d0c0d4f9b01..f598f0708a7 100755 --- a/scripts/patterns-reorg/main.py +++ b/scripts/patterns-reorg/main.py @@ -21,6 +21,7 @@ from models import determine_redirects from entries import TOP_LEVEL_ENTRIES +from deleted_entries import DELETED_PAGES def create_parser() -> ArgumentParser: @@ -53,7 +54,7 @@ def write_guides_dir() -> None: def write_redirects_file() -> None: fp = Path("scripts/patterns-reorg/redirects.json") - redirects = determine_redirects(TOP_LEVEL_ENTRIES) + redirects = determine_redirects((*TOP_LEVEL_ENTRIES, *DELETED_PAGES)) text = json.dumps(redirects, indent=2) + "\n" fp.write_text(text) diff --git a/scripts/patterns-reorg/models.py b/scripts/patterns-reorg/models.py index 52b4082f6e4..0182a15ec0f 100644 --- a/scripts/patterns-reorg/models.py +++ b/scripts/patterns-reorg/models.py @@ -96,6 +96,12 @@ def entries_as_markdown_list( return "\n".join(result) +@dataclass(frozen=True) +class DeletedPage: + redirect_to: str + old_slug: str + + def filter_entries( entries: tuple[Entry, ...], *, ignore: set[Entry] ) -> tuple[Entry, ...]: @@ -109,14 +115,33 @@ def filter_entries( result.append(new_entry) return tuple(result) +def _add_redirect_to_dict(redirects: dict[str, str], old_url: str, redirect_to: str)-> None: + redirects[old_url] = redirect_to + # We need to add two links for each index entry because we can + # have two links possible. For example, `/run/index` and `/run` + # point to the same page. + old_folder, old_file_name = old_url.split('/') + if old_file_name == "index": + redirects[f"{old_folder}"] = redirect_to + def determine_redirects( - entries: tuple[Entry, ...], *, prefix: str = "" + entries: tuple[Entry | DeletedPage, ...], *, prefix: str = "" ) -> dict[str, str]: result = {} for entry in entries: - if entry.slug and entry.from_file: + if isinstance(entry, Entry): + result.update(determine_redirects(entry.children)) + + if entry.slug is None or not entry.from_file: + continue + old_url = str(PurePath(entry.from_file).with_suffix("")) - result[old_url] = f"{prefix}{entry.slug.removeprefix('/')}" - result.update(determine_redirects(entry.children)) + redirect_to = f"{prefix}{entry.slug.removeprefix('/')}" + _add_redirect_to_dict(result, old_url, redirect_to) + + elif isinstance(entry, DeletedPage): + redirect_to = f"{prefix}{entry.redirect_to.removeprefix('/')}" + _add_redirect_to_dict(result, entry.old_slug, redirect_to) + return result diff --git a/scripts/patterns-reorg/redirects.json b/scripts/patterns-reorg/redirects.json index edb106cd788..f3b07ae3a06 100644 --- a/scripts/patterns-reorg/redirects.json +++ b/scripts/patterns-reorg/redirects.json @@ -18,6 +18,7 @@ "build/interoperate-qiskit-qasm3": "interoperate-qiskit-qasm3", "build/qasm-feature-table": "qasm-feature-table", "transpile/index": "transpile", + "transpile": "transpile", "transpile/transpiler-stages": "transpiler-stages", "transpile/transpile-with-pass-managers": "transpile-with-pass-managers", "transpile/defaults-and-configuration-options": "defaults-and-configuration-options", @@ -32,6 +33,7 @@ "transpile/qiskit-transpiler-service": "qiskit-transpiler-service", "transpile/ai-transpiler-passes": "ai-transpiler-passes", "verify/index": "debugging-tools", + "verify": "debugging-tools", "verify/simulate-with-qiskit-primitives": "simulate-with-qiskit-sdk-primitives", "verify/simulate-with-qiskit-aer": "simulate-with-qiskit-aer", "verify/local-testing-mode": "local-testing-mode", @@ -65,5 +67,11 @@ "build/circuit-visualization": "visualize-circuits", "verify/plot-quantum-states": "plot-quantum-states", "run/visualize-results": "visualize-results", - "run/quantum-serverless": "qiskit-serverless" + "run/quantum-serverless": "qiskit-serverless", + "build/index": "map-problem-to-circuits", + "build": "map-problem-to-circuits", + "run/index": "execute-on-hardware", + "run": "execute-on-hardware", + "start/index": "", + "start": "" }