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

API Descriptions Update #1940

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

API Descriptions Update #1940

wants to merge 21 commits into from

Conversation

Bashamega
Copy link
Contributor

fixes #1937

Copy link
Contributor

Thanks for the PR!

This section of the codebase is owned by @saschanaz - if they write a comment saying "LGTM" then it will be merged.

@saschanaz
Copy link
Contributor

We still depend on that, so we can't just remove it until we get a new mdn/content dependency?

@Bashamega
Copy link
Contributor Author

We still depend on that, so we can't just remove it until we get a new mdn/content dependency?

I know

src/build.ts Outdated

const OWNER = "mdn";
const REPO = "content";
const BASE_PATH = "files/en-us/web/api";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think maybe we should add a submodule so that we can make the build more reproducible locally

Copy link
Contributor Author

@Bashamega Bashamega Mar 15, 2025

Choose a reason for hiding this comment

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

Sure, I can do that
I will get started on that 😃

@Bashamega Bashamega marked this pull request as ready for review March 15, 2025 15:57
@Bashamega
Copy link
Contributor Author

Hello @saschanaz,
I have created a script to generate the JSON, ran the baseline command, and fixed some linting problems, but I don't know how to solve the error you see in the logs. It is just one error.

@saschanaz
Copy link
Contributor

Maybe npm i?

@Bashamega
Copy link
Contributor Author

Maybe npm i?

Hello:)
How will npm i help?
I ran it and it didn't do anything

@saschanaz
Copy link
Contributor

saschanaz commented Mar 16, 2025

I mean npm i && npm run build && npm run baseline-accept? Because it seems like it's caused by mismatch of installed dependency version. npm i fixes that.

@Bashamega
Copy link
Contributor Author

I mean npm i && npm run build && npm run baseline-accept? Because it seems like it's caused by mismatch of dependency version. npm i fixes that.
oh okay

@Bashamega Bashamega requested a review from saschanaz March 16, 2025 09:50
@@ -289,7 +297,11 @@ declare var ByteLengthQueuingStrategy: {
new(init: QueuingStrategyInit): ByteLengthQueuingStrategy;
};

/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CompressionStream) */
/**
* Of the {{domxref('Compression Streams API','','',' ')}} is an API for compressing a stream of data.
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks weird. Now that we are at it, maybe we should remove:

const removeVerboseIntroductions: [RegExp, string][] = [
[
/^(The|A) ${name} interface of (the\s*)*((?:(?!API)[A-Za-z\d\s])+ API)/,
"This $3 interface ",
],
[
/^(The|A) ${name} (interface|event|object) (is|represents|describes|defines)?/,
"",
],
[
/^An object implementing the ${name} interface (is|represents|describes|defines)/,
"",
],
[/^The ${name} is an interface representing/, ""],
[/^This type (is|represents|describes|defines)?/, ""],
[
/^The (((?:(?!API)[A-Za-z\s])+ API)) ${name} (represents|is|describes|defines)/,
"The $1 ",
],
];

Because I don't think it makes sense to deal with all kinds of human language without accidentally breaking things.

Copy link
Contributor Author

@Bashamega Bashamega Mar 16, 2025

Choose a reason for hiding this comment

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

I think it would be easier if we converted the Markdown to HTML. I can utilize Cheerio like the mdn and get the summary like mdn. If you think this is a good way to do it, I can implement it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why that's needed here, can you explain more?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh you mean the domxref thing. Hmm.

Copy link
Contributor

@saschanaz saschanaz Mar 16, 2025

Choose a reason for hiding this comment

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

(I was talking about the sentence unnaturally starting with "Of the Compression Stream API is an API"... (It's because the above code cuts the initial part of the sentence.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the reason that I made all these regexes is to avoid the weird template code. But if I convert the markdown to HTML first, I think it would be easier to extract the data without the weird templates

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh

Copy link
Contributor

Choose a reason for hiding this comment

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

If using Cheerio is easy to remove domxref thing then I guess it's worth trying!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If using Cheerio is easy to remove domxref thing then I guess it's worth trying!

Okay

package.json Outdated
@@ -13,6 +13,7 @@
],
"scripts": {
"build": "tsc && node ./lib/build.js",
"generate": "tsc && node ./lib/generateDescriptions.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be part of build instead (ideally called by lib/build.js?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I can do that :)

@@ -289,7 +297,11 @@ declare var ByteLengthQueuingStrategy: {
new(init: QueuingStrategyInit): ByteLengthQueuingStrategy;
};

/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CompressionStream) */
/**
* Of the {{domxref('Compression Streams API','','',' ')}} is an API for compressing a stream of data.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why that's needed here, can you explain more?

Comment on lines +22 to +26
return trimmed
.replace(/\{\{domxref\(["'][^"']+["'],\s*["']([^"']+)["']\)\}\}/g, "$1") // Extract second argument from domxref
.replace(/\{\{domxref\(["']([^"']+)["']\)\}\}/g, "$1") // Extract single-argument domxref
.replace(/\{\{[^}]+\}\}/g, "") // Remove other MDN templates like {{CSSRef}}
.replace(/<[^>]+>/g, "") // Remove HTML tags

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<script
, which may cause an HTML element injection vulnerability.
@Bashamega
Copy link
Contributor Author

We need to figure out a way to compile the markdown without the weird templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: Automate API Descriptions Update via GitHub Action
2 participants