-
Notifications
You must be signed in to change notification settings - Fork 131
Add check that page title is in sync with h1 and metadata #3669
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
Merged
+447
−155
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
fb15293
Added a new function and test case for mismatched title and heading
GantaRoja 176bc95
lint errors fixed
GantaRoja 9ab781c
separaeted tests removed consoles
GantaRoja 32cfd9d
lint error fixed
GantaRoja 5b5fd21
called the function and rename of checkimages to checkMarkdoen
GantaRoja 86b5296
checkpoint
GantaRoja 4e6ac5f
modified check file
GantaRoja 94d1e01
corrected packagejson file
GantaRoja 6a9af5b
ignored files starts with doc/spi
GantaRoja 8012257
moved parsing step out of the function
GantaRoja ee77032
moved helper function to a new file
GantaRoja cae7d70
modified few files
GantaRoja de37f43
combined test caeses using describe
GantaRoja 29e01b7
Merge branch 'main' of https://github.com/Qiskit/documentation into R…
GantaRoja 806bd3c
Merge branch 'main' of https://github.com/Qiskit/documentation into R…
GantaRoja 73f63d5
commiting to review the changes
GantaRoja 547d48c
./fixed errors
GantaRoja a9b4f20
added .ipynb ext files to allowlist
GantaRoja 5acb713
added a new .ipynb ext files to allowlist
GantaRoja 099dbee
formatted markdown input in test file
GantaRoja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// This code is a Qiskit project. | ||
// | ||
// (C) Copyright IBM 2025. | ||
// | ||
// This code is licensed under the Apache License, Version 2.0. You may | ||
// obtain a copy of this license in the LICENSE file in the root directory | ||
// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// Any modifications or derivative works of this code must retain this | ||
// copyright notice, and modified files need to carry a notice indicating | ||
// that they have been altered from the originals. | ||
|
||
import { globby } from "globby"; | ||
import yargs from "yargs/yargs"; | ||
import { hideBin } from "yargs/helpers"; | ||
|
||
import { collectInvalidImageErrors } from "../lib/markdownImages.js"; | ||
import { readMarkdown } from "../lib/markdownReader.js"; | ||
import { collectHeadingTitleMismatch } from "../lib/markdownTitles.js"; | ||
import { parseMarkdown } from "../lib/markdownUtils"; | ||
|
||
const IGNORE_TITLE_MISMATCHES: string[] = [ | ||
"docs/migration-guides/external-providers-primitives-v2.mdx", | ||
"docs/migration-guides/local-simulators.mdx", | ||
"docs/migration-guides/metapackage-migration.mdx", | ||
"docs/migration-guides/qiskit-1.0-features.mdx", | ||
"docs/migration-guides/qiskit-1.0-installation.mdx", | ||
"docs/migration-guides/qiskit-algorithms-module.mdx", | ||
"docs/migration-guides/qiskit-backend-primitives.mdx", | ||
"docs/migration-guides/qiskit-backendv1-to-v2.mdx", | ||
"docs/migration-guides/qiskit-opflow-module.mdx", | ||
"docs/migration-guides/qiskit-runtime-from-ibm-provider.mdx", | ||
"docs/migration-guides/qiskit-runtime-from-ibmq-provider.mdx", | ||
"docs/migration-guides/qiskit-runtime-options.mdx", | ||
"docs/guides/access-groups.mdx", | ||
"docs/migration-guides/v2-primitives.mdx", | ||
"docs/guides/execution-modes.mdx", | ||
"docs/guides/install-qiskit-source.mdx", | ||
"docs/guides/manage-cost.mdx", | ||
"docs/guides/plans-overview.mdx", | ||
"docs/guides/qiskit-addons-aqc.mdx", | ||
"docs/guides/qiskit-addons-sqd.mdx", | ||
"docs/guides/qiskit-code-assistant-vscode.mdx", | ||
"docs/guides/qiskit-function-templates.mdx", | ||
"docs/guides/serverless.mdx", | ||
"docs/open-source/code-of-conduct.mdx", | ||
"docs/open-source/create-a-provider.mdx", | ||
"docs/support/execution-modes-faq.mdx", | ||
"docs/support/faq.mdx", | ||
"learning/index.mdx", | ||
"learning/courses/basics-of-quantum-information/exam.mdx", | ||
"learning/courses/basics-of-quantum-information/index.mdx", | ||
"learning/courses/foundations-of-quantum-error-correction/index.mdx", | ||
"learning/courses/fundamentals-of-quantum-algorithms/exam.mdx", | ||
"learning/courses/fundamentals-of-quantum-algorithms/index.mdx", | ||
"learning/courses/quantum-business-foundations/business-impacts.mdx", | ||
"learning/courses/quantum-business-foundations/exam.mdx", | ||
"learning/courses/quantum-business-foundations/quantum-computing-fundamentals.mdx", | ||
"learning/courses/quantum-business-foundations/quantum-technology.mdx", | ||
"learning/courses/quantum-business-foundations/start-your-quantum-journey.mdx", | ||
"learning/courses/quantum-chem-with-vqe/exam.mdx", | ||
"learning/courses/quantum-diagonalization-algorithms/exam.mdx", | ||
"learning/courses/quantum-machine-learning/exam.mdx", | ||
"learning/courses/quantum-safe-cryptography/exam.mdx", | ||
"learning/courses/utility-scale-quantum-computing/classical-simulation.mdx", | ||
"learning/courses/variational-algorithm-design/exam.mdx", | ||
]; | ||
|
||
const allErrors: string[] = []; | ||
|
||
interface Arguments { | ||
[x: string]: unknown; | ||
apis: boolean; | ||
} | ||
|
||
const readArgs = (): Arguments => { | ||
return yargs(hideBin(process.argv)) | ||
.version(false) | ||
.option("apis", { | ||
type: "boolean", | ||
default: false, | ||
description: | ||
"Check files in the current and dev versions of the API docs.", | ||
}) | ||
.parseSync(); | ||
}; | ||
|
||
async function main() { | ||
const args = readArgs(); | ||
const files = await determineContentFiles(args); | ||
|
||
for (const file of files) { | ||
const markdown = await readMarkdown(file); | ||
const tree = parseMarkdown(markdown); | ||
const imageErrors = await collectInvalidImageErrors(tree); | ||
const mismatchedTitleHeadingErrors = | ||
IGNORE_TITLE_MISMATCHES.includes(file) || file.startsWith("docs/api") | ||
? new Set<string>() | ||
: await collectHeadingTitleMismatch(tree); | ||
|
||
//Collect all errors for this file | ||
const errorsInFile: string[] = [ | ||
...imageErrors, | ||
...mismatchedTitleHeadingErrors, | ||
]; | ||
|
||
if (errorsInFile.length) { | ||
allErrors.push( | ||
`Error in file '${file}':\n\t- ${errorsInFile.join("\n\t- ")}\n`, | ||
); | ||
} | ||
} | ||
|
||
// Final error report | ||
if (allErrors.length) { | ||
allErrors.forEach((error) => console.log(error)); | ||
console.error( | ||
"💔 Some issues were found in your Markdown files. Please fix them before proceeding.\n" + | ||
"Image help: https://github.com/Qiskit/documentation#images\n" + | ||
"Title/Heading help: https://github.com/Qiskit/documentation#titles-and-headings\n", | ||
frankharkins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
process.exit(1); | ||
} | ||
|
||
console.log("✅ All files passed validation.\n"); | ||
} | ||
|
||
async function determineContentFiles(args: Arguments): Promise<string[]> { | ||
// We always skip historical versions to simplify the code and to have a faster script. | ||
// Even though it is possible for someone to add a new image without alt text to a | ||
// historical version that wasn't in the original release, that's very unlikely. | ||
// If it happens, it would probably be a backport from latest or dev, and the linter in | ||
// the API repo should catch it. | ||
// | ||
// If an image is missed by the API repo's linter, it will still have an alt text defined, | ||
// although it won't be very useful. That's because Sphinx auto-generates alt text. | ||
const globs = [ | ||
"{docs,learning}/**/*.{ipynb,mdx}", | ||
args.apis ? "!docs/api/*/([0-9]*)/*.mdx" : "!docs/api/**/*.mdx", | ||
// Remove when https://github.com/Qiskit/documentation/issues/2564 is fixed | ||
`!docs/api/qiskit/release-notes/*.mdx`, | ||
]; | ||
|
||
return await globby(globs); | ||
} | ||
|
||
main().then(() => process.exit()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.