Update patterns redirects file (#1594)

The PR updates the `scripts/patterns-reorg/redirects.json` file to a
more convenient format that aligns better with our middleware. Having
the `/` at the beginning of the old paths and the `/guides/` prefix in
the new paths will allow us to have a more generic redirect file that
could be used in the future for different URLs than patterns, and it
will help us to set the redirects with a simpler logic.

e.g., `url.pathname = REDIRECTS[url.pathname]`

The PR also adds a missing redirect for `/start/latest-updates`.
This commit is contained in:
Arnau Casau 2024-06-26 21:24:39 +02:00 committed by GitHub
parent 14c0363958
commit 7a3029dab2
3 changed files with 86 additions and 85 deletions

View File

@ -24,7 +24,7 @@ from entries import TOP_LEVEL_ENTRIES
from deleted_entries import DELETED_PAGES
OLD_FOLDERS = ["start", "run", "verify", "transpile", "build"]
REDIRECTS = determine_redirects((*TOP_LEVEL_ENTRIES, *DELETED_PAGES))
REDIRECTS = determine_redirects((*TOP_LEVEL_ENTRIES, *DELETED_PAGES), prefix="/guides")
def create_parser() -> ArgumentParser:

View File

@ -123,7 +123,7 @@ def _add_redirect_to_dict(
# 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("/")
old_folder, old_file_name = old_url.rsplit("/",1)
if old_file_name == "index":
redirects[f"{old_folder}"] = redirect_to
@ -134,17 +134,17 @@ def determine_redirects(
result = {}
for entry in entries:
if isinstance(entry, Entry):
result.update(determine_redirects(entry.children))
result.update(determine_redirects(entry.children, prefix=prefix))
if entry.slug is None or not entry.from_file:
continue
old_url = str(PurePath(entry.from_file).with_suffix(""))
redirect_to = f"{prefix}{entry.slug.removeprefix('/')}"
old_url = f"/{str(PurePath(entry.from_file).with_suffix(''))}"
redirect_to = f"{prefix}{entry.slug}"
_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)
redirect_to = f"{prefix}{entry.redirect_to}"
_add_redirect_to_dict(result, f"/{entry.old_slug}", redirect_to)
return result

View File

@ -1,80 +1,81 @@
{
"start/install": "install-qiskit",
"start/setup-channel": "setup-channel",
"start/hello-world": "hello-world",
"start/install-qiskit-source": "install-qiskit-source",
"start/configure-qiskit-local": "configure-qiskit-local",
"build/circuit-library": "circuit-library",
"build/circuit-construction": "construct-circuits",
"build/classical-feedforward-and-control-flow": "classical-feedforward-and-control-flow",
"build/unitary-synthesis": "synthesize-unitary-operators",
"build/bit-ordering": "bit-ordering",
"build/save-circuits": "save-circuits",
"build/operators-overview": "operators-overview",
"build/specify-observables-pauli": "specify-observables-pauli",
"build/operator-class": "operator-class",
"build/pulse": "pulse",
"build/introduction-to-qasm": "introduction-to-qasm",
"build/interoperate-qiskit-qasm2": "interoperate-qiskit-qasm2",
"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",
"transpile/set-optimization": "set-optimization",
"transpile/common-parameters": "common-parameters",
"transpile/representing_quantum_computers": "represent-quantum-computers",
"transpile/dynamical-decoupling-pass-manager": "dynamical-decoupling-pass-manager",
"transpile/custom-transpiler-pass": "custom-transpiler-pass",
"transpile/custom-backend": "custom-backend",
"transpile/transpiler-plugins": "transpiler-plugins",
"transpile/create-a-transpiler-plugin": "create-transpiler-plugin",
"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",
"verify/building_noise_models": "build-noise-models",
"verify/stabilizer-circuit-simulation": "simulate-stabilizer-circuits",
"run/primitives": "primitives",
"run/primitives-get-started": "get-started-with-primitives",
"run/primitives-examples": "primitives-examples",
"run/configure-runtime-compilation": "configure-runtime-compilation",
"run/configure-error-mitigation": "configure-error-mitigation",
"run/advanced-runtime-options": "advanced-runtime-options",
"run/error-mitigation-explanation": "error-mitigation-and-suppression-techniques",
"run/execution-modes": "execution-modes",
"run/sessions": "sessions",
"run/run-jobs-in-session": "run-jobs-session",
"run/run-jobs-batch": "run-jobs-batch",
"run/circuit-execution": "repetition-rate-execution",
"run/monitor-job": "monitor-job",
"run/estimate-job-run-time": "estimate-job-run-time",
"run/minimize-time": "minimize-time",
"run/max-execution-time": "max-execution-time",
"run/save-jobs": "save-jobs",
"run/execution-modes-faq": "execution-modes-faq",
"run/processor-types": "processor-types",
"run/system-information": "system-information",
"run/get-backend-information": "get-backend-information",
"run/native-gates": "native-gates",
"run/retired-systems": "retired-systems",
"run/dynamic-circuits-considerations": "dynamic-circuits-considerations",
"run/instances": "instances",
"run/fair-share-queue": "fair-share-scheduler",
"run/manage-cost": "manage-cost",
"build/circuit-visualization": "visualize-circuits",
"verify/plot-quantum-states": "plot-quantum-states",
"run/visualize-results": "visualize-results",
"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": ""
"/start/install": "/guides/install-qiskit",
"/start/setup-channel": "/guides/setup-channel",
"/start/hello-world": "/guides/hello-world",
"/start/latest-updates": "/guides/latest-updates",
"/start/install-qiskit-source": "/guides/install-qiskit-source",
"/start/configure-qiskit-local": "/guides/configure-qiskit-local",
"/build/circuit-library": "/guides/circuit-library",
"/build/circuit-construction": "/guides/construct-circuits",
"/build/classical-feedforward-and-control-flow": "/guides/classical-feedforward-and-control-flow",
"/build/unitary-synthesis": "/guides/synthesize-unitary-operators",
"/build/bit-ordering": "/guides/bit-ordering",
"/build/save-circuits": "/guides/save-circuits",
"/build/operators-overview": "/guides/operators-overview",
"/build/specify-observables-pauli": "/guides/specify-observables-pauli",
"/build/operator-class": "/guides/operator-class",
"/build/pulse": "/guides/pulse",
"/build/introduction-to-qasm": "/guides/introduction-to-qasm",
"/build/interoperate-qiskit-qasm2": "/guides/interoperate-qiskit-qasm2",
"/build/interoperate-qiskit-qasm3": "/guides/interoperate-qiskit-qasm3",
"/build/qasm-feature-table": "/guides/qasm-feature-table",
"/transpile/index": "/guides/transpile",
"/transpile": "/guides/transpile",
"/transpile/transpiler-stages": "/guides/transpiler-stages",
"/transpile/transpile-with-pass-managers": "/guides/transpile-with-pass-managers",
"/transpile/defaults-and-configuration-options": "/guides/defaults-and-configuration-options",
"/transpile/set-optimization": "/guides/set-optimization",
"/transpile/common-parameters": "/guides/common-parameters",
"/transpile/representing_quantum_computers": "/guides/represent-quantum-computers",
"/transpile/dynamical-decoupling-pass-manager": "/guides/dynamical-decoupling-pass-manager",
"/transpile/custom-transpiler-pass": "/guides/custom-transpiler-pass",
"/transpile/custom-backend": "/guides/custom-backend",
"/transpile/transpiler-plugins": "/guides/transpiler-plugins",
"/transpile/create-a-transpiler-plugin": "/guides/create-transpiler-plugin",
"/transpile/qiskit-transpiler-service": "/guides/qiskit-transpiler-service",
"/transpile/ai-transpiler-passes": "/guides/ai-transpiler-passes",
"/verify/index": "/guides/debugging-tools",
"/verify": "/guides/debugging-tools",
"/verify/simulate-with-qiskit-primitives": "/guides/simulate-with-qiskit-sdk-primitives",
"/verify/simulate-with-qiskit-aer": "/guides/simulate-with-qiskit-aer",
"/verify/local-testing-mode": "/guides/local-testing-mode",
"/verify/building_noise_models": "/guides/build-noise-models",
"/verify/stabilizer-circuit-simulation": "/guides/simulate-stabilizer-circuits",
"/run/primitives": "/guides/primitives",
"/run/primitives-get-started": "/guides/get-started-with-primitives",
"/run/primitives-examples": "/guides/primitives-examples",
"/run/configure-runtime-compilation": "/guides/configure-runtime-compilation",
"/run/configure-error-mitigation": "/guides/configure-error-mitigation",
"/run/advanced-runtime-options": "/guides/advanced-runtime-options",
"/run/error-mitigation-explanation": "/guides/error-mitigation-and-suppression-techniques",
"/run/execution-modes": "/guides/execution-modes",
"/run/sessions": "/guides/sessions",
"/run/run-jobs-in-session": "/guides/run-jobs-session",
"/run/run-jobs-batch": "/guides/run-jobs-batch",
"/run/circuit-execution": "/guides/repetition-rate-execution",
"/run/monitor-job": "/guides/monitor-job",
"/run/estimate-job-run-time": "/guides/estimate-job-run-time",
"/run/minimize-time": "/guides/minimize-time",
"/run/max-execution-time": "/guides/max-execution-time",
"/run/save-jobs": "/guides/save-jobs",
"/run/execution-modes-faq": "/guides/execution-modes-faq",
"/run/processor-types": "/guides/processor-types",
"/run/system-information": "/guides/system-information",
"/run/get-backend-information": "/guides/get-backend-information",
"/run/native-gates": "/guides/native-gates",
"/run/retired-systems": "/guides/retired-systems",
"/run/dynamic-circuits-considerations": "/guides/dynamic-circuits-considerations",
"/run/instances": "/guides/instances",
"/run/fair-share-queue": "/guides/fair-share-scheduler",
"/run/manage-cost": "/guides/manage-cost",
"/build/circuit-visualization": "/guides/visualize-circuits",
"/verify/plot-quantum-states": "/guides/plot-quantum-states",
"/run/visualize-results": "/guides/visualize-results",
"/run/quantum-serverless": "/guides/qiskit-serverless",
"/build/index": "/guides/map-problem-to-circuits",
"/build": "/guides/map-problem-to-circuits",
"/run/index": "/guides/execute-on-hardware",
"/run": "/guides/execute-on-hardware",
"/start/index": "/guides",
"/start": "/guides"
}