Skip to content

doc: fix stability 1.x links excluding the decimal digit #58783

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

Conversation

dario-piotrowicz
Copy link
Member

@dario-piotrowicz dario-piotrowicz commented Jun 21, 2025

Pretty minor, this is just addressing a minimal UI quirk I noticed with the Stability 1.x links where the decimal digits are not included in the hyperlink

PS: I've also moved the regex outside of the preprocessElements function, as there is no reason/benefit to have the regex rebuilt for every file (having it outside might save some precious nanoseconds when building the docs 😅).

Before

before

After

after

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/web-infra

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. tools Issues and PRs related to the tools directory. labels Jun 21, 2025
@dario-piotrowicz dario-piotrowicz force-pushed the dario/doc/stability-1-link-fix branch from 0c3c90c to 391b587 Compare June 21, 2025 22:24
Copy link

@Hardanish-Singh Hardanish-Singh left a comment

Choose a reason for hiding this comment

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

LGTM!

@dario-piotrowicz dario-piotrowicz added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jun 22, 2025
@@ -325,7 +326,7 @@ export function preprocessElements({ filename }) {
// Insert div with prefix and number
node.children.unshift({
type: 'html',
value: `<div class="api_stability api_stability_${number}">` +
value: `<div class="api_stability api_stability_${parseInt(number)}">` +
Copy link
Member

Choose a reason for hiding this comment

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

parseInt will only grab the numeric pieces of "number" right?

Copy link
Member Author

@dario-piotrowicz dario-piotrowicz Jun 22, 2025

Choose a reason for hiding this comment

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

Yes, in the regex that the part for number is /\d(?:\.\d)? meaning that the number matched value can be a single digit optionally followed by a dot followed by another digit, parseInt run on such numbers/strings always returns the integer part of the number:
Screenshot at 2025-06-22 18-50-14

And that's the part we need based on the css classes we have:

.api_stability_0 {
background-color: var(--red1);
}
.api_stability_1 {
background-color: var(--red3);
}
.api_stability_2 {
background-color: var(--green2);
}
.api_stability_3 {
background-color: var(--blue1);
}

Copy link
Member

Choose a reason for hiding this comment

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

I used the same trick in the web generator :-)

Copy link
Member

Choose a reason for hiding this comment

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

I just wanted to confirm. I recall either parseInt or Number() parse the numeric parseable stuff until it finds something non-numeric.

Copy link
Member

Choose a reason for hiding this comment

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

No, not until it finds something non-numeric. It parses the float since it's a valid number, and flattens it to an integer.

@avivkeller
Copy link
Member

avivkeller commented Jun 23, 2025

Note to web infra teams: this doesn't need to be ported to api-docs-tooling, I (independently from this) changed the logic to something similar in the web generator PR.

@dario-piotrowicz
Copy link
Member Author

Note to web infra teams: this doesn't need to be ported to api-docs-tooling, I (independently from this) changed the logic to something similar in the web generator PR.

Thanks, I was about to ask someone at some point if this needed porting (as I haven't looked too much into the new tooling I must admit 😓) but you saved me the effort 🫶

@dario-piotrowicz dario-piotrowicz added the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 23, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 23, 2025
@nodejs-github-bot nodejs-github-bot merged commit d8de8f3 into nodejs:main Jun 23, 2025
25 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in d8de8f3

@ovflowd
Copy link
Member

ovflowd commented Jun 23, 2025

I wish I could have landed this haha; Ah how it sucks not being a collaborator anymore lol

RafaelGSS pushed a commit that referenced this pull request Jun 24, 2025
PR-URL: #58783
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. doc Issues and PRs related to the documentations. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants