Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow manually created class pages #1382

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions scripts/lib/api/TocGrouping.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,27 @@ async function getIndexModuleGroups(fp: string): Promise<ModuleGroup[]> {
const result: ModuleGroup[] = [];
let currentGroup: ModuleGroup = [];
for (const line of rawIndex.split("\n")) {
if (line.startsWith("* ")) {
if (line.includes("qiskit.")) {
const module = extractModuleName(line);
currentGroup.push(module);
// Each ModuleGroup represents an unordered list of entries starting with `*`.
// So, when we stop encountering `*`, we need to start a new ModuleGroup.
if (!line.startsWith("* ")) {
if (currentGroup.length) {
result.push(currentGroup);
currentGroup = [];
}
continue;
} else if (currentGroup.length) {
result.push(currentGroup);
currentGroup = [];
}

// Certain classes like QuantumCircuit in Qiskit 1.1+ have manually
// created pages. Those pages show up in index.mdx as top-level entries,
// but they are not top-level entries in the left ToC. This is expected.
// So, we allow the index to diverge from the left ToC.
//
// This is looking for e.g. '[`QuantumCircuit` class](qiskit.circuit.QuantumCircuit)'
const isDedicatedClassPage = line.includes(" class](");
if (isDedicatedClassPage) continue;

const module = extractModuleName(line);
currentGroup.push(module);
}
return result;
}
Expand Down
6 changes: 5 additions & 1 deletion scripts/lib/api/generateApiComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import remarkStringify from "remark-stringify";
import { ApiType } from "./Metadata";
import {
getLastPartFromFullIdentifier,
removeSuffix,
APOSTROPHE_HEX_CODE,
} from "../stringUtils";

Expand Down Expand Up @@ -142,7 +143,10 @@ function prepareClassOrExceptionProps(
modifiers,
};

const pageHeading = $dl.siblings("h1").text();
let pageHeading = $dl.siblings("h1").text();
// Manually created class pages like Qiskit 1.1+'s `QuantumCircuit`
// sometimes have ' class' in their h1.
pageHeading = removeSuffix(pageHeading, " class");
if (id.endsWith(pageHeading) && pageHeading != "") {
// Page is already dedicated to the class
return {
Expand Down
Loading