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

Update legacy release notes links #865

Merged
merged 7 commits into from
Feb 26, 2024

Conversation

arnaucasau
Copy link
Collaborator

@arnaucasau arnaucasau commented Feb 21, 2024

Part of #755

This PR changes the legacy release notes links to point to the qiskit 0.45 version folder.

How the change was done

I created a little script to transform every link in a release note file and re-write it in the same destination. I named it updateLinks.ts.

import { zxMain } from "../lib/zx";
import { globby } from "globby";
import { pathExists, getRoot } from "../lib/fs";
import { readFile, writeFile } from "fs/promises";
import transformLinks from "transform-markdown-links";

zxMain(async () => {
  const allVersions = (
    await globby("docs/api/qiskit/release-notes/[!index]*")
  ).map((releaseNotesPath) =>
    releaseNotesPath.split("/").pop()!.split(".").slice(0, -1).join("."),
  );

  for (const releaseNotesVersion of allVersions) {
    const source = `${getRoot()}/docs/api/qiskit/release-notes/${releaseNotesVersion}.md`;
    if (await pathExists(source)) {
      updateLinksFile('qiskit', releaseNotesVersion, source, source);
    }
  }
});

async function updateLinksFile(pkgName: string, versionWithoutPatch: string, source: string, dest: string) {
  let markdown = await readFile(source, { encoding: "utf8" });

  const regexAbsolutePath = new RegExp(
    "/api/" + pkgName + "/(?!release-notes)(?![0-9])",
  );

  markdown = transformLinks(markdown, (link, _) =>
    link.replace(regexAbsolutePath, `/api/${pkgName}/0.45/`),
  );

  await writeFile(dest, markdown);
}

To execute the script using npm run update-legacy-links you can modify the package.json file by adding the following line in the scripts section:

"update-legacy-links": "node -r esbuild-register scripts/commands/updateLinks.ts"

@arnaucasau arnaucasau marked this pull request as ready for review February 21, 2024 17:04
@qiskit-bot
Copy link
Contributor

Thanks for contributing to Qiskit documentation!

Before your PR can be merged, it will first need to pass continuous
integration tests and be reviewed. Sometimes the review process can be slow,
so please be patient.

@arnaucasau arnaucasau changed the title [do not merge] Update legacy release notes links Update legacy release notes links Feb 22, 2024
@arnaucasau arnaucasau marked this pull request as draft February 22, 2024 19:19
@Eric-Arellano
Copy link
Collaborator

Awesome! There are still a lot of links to 0.46 in these release notes, which would be good to point to 0.45 instead. Those can be a simple find and replace for /api/qiskit/0.45/.

Also you can simplify the link checker toLoad logic.

@arnaucasau arnaucasau marked this pull request as ready for review February 26, 2024 11:35
@qiskit-bot
Copy link
Contributor

Thanks for contributing to Qiskit documentation!

Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌

Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@Eric-Arellano Eric-Arellano merged commit 9832c8a into Qiskit:main Feb 26, 2024
5 of 6 checks passed
@arnaucasau arnaucasau deleted the AC/legacy-release-notes-links branch March 11, 2024 08:29
frankharkins pushed a commit to frankharkins/documentation that referenced this pull request Jul 22, 2024
Part of Qiskit#755

This PR changes the legacy release notes links to point to the qiskit
0.45 version folder.

### How the change was done

I created a little script to transform every link in a release note file
and re-write it in the same destination. I named it `updateLinks.ts`.

```ts
import { zxMain } from "../lib/zx";
import { globby } from "globby";
import { pathExists, getRoot } from "../lib/fs";
import { readFile, writeFile } from "fs/promises";
import transformLinks from "transform-markdown-links";

zxMain(async () => {
  const allVersions = (
    await globby("docs/api/qiskit/release-notes/[!index]*")
  ).map((releaseNotesPath) =>
    releaseNotesPath.split("/").pop()!.split(".").slice(0, -1).join("."),
  );

  for (const releaseNotesVersion of allVersions) {
    const source = `${getRoot()}/docs/api/qiskit/release-notes/${releaseNotesVersion}.md`;
    if (await pathExists(source)) {
      updateLinksFile('qiskit', releaseNotesVersion, source, source);
    }
  }
});

async function updateLinksFile(pkgName: string, versionWithoutPatch: string, source: string, dest: string) {
  let markdown = await readFile(source, { encoding: "utf8" });

  const regexAbsolutePath = new RegExp(
    "/api/" + pkgName + "/(?!release-notes)(?![0-9])",
  );

  markdown = transformLinks(markdown, (link, _) =>
    link.replace(regexAbsolutePath, `/api/${pkgName}/0.45/`),
  );

  await writeFile(dest, markdown);
}


```

To execute the script using `npm run update-legacy-links` you can modify
the `package.json` file by adding the following line in the `scripts`
section:

```ts
"update-legacy-links": "node -r esbuild-register scripts/commands/updateLinks.ts"
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants