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

[microsite] Use Docusaurus@canary #17549

Merged
merged 4 commits into from
Apr 28, 2023
Merged

Conversation

benjdlambert
Copy link
Member

@benjdlambert benjdlambert commented Apr 27, 2023

Ok - Controversial I know, but thinking that it could be good.

Right now the microsite is broken because of the MDX parser @v1 which is used in Docusarus, which means that when people write API doc comments, they get converted into Markdown and then get parsed by the MDX parser. There's been a few cases where PR's have broken the microsite as we don't build the microsite for any API doc changes.

facebook/docusaurus#8288 was merged recently, which switches MDX@1 to MDX@2 which gives us many benefits, performance, and better parsing, which means that we can be more confident with doc changes moving forward and they wont break our microsite.

It's also got some pre-processing in here, so we can strip HTML comments (which aren't supported at all in MDX2) in one place and do it cleanly in the loader config for all .md files rather than just the docs/reference like before.

The <!-- prettier-ignore --> is an unfortunate side effect that {/* truncate */} gets converted to {/_ truncate _/} which is not what we want.

Microsite is currently broken with the error message ReferenceError: pluginId is not defined when parsing the generated API docs for the new FrontendHostDiscovery. So it's basically when it's parsing this:

* - target: https://internal.example.com/secure/api/{{pluginId}}

And

* the provided `pathPattern` appended. The default path pattern is `"/api/{{ pluginId }}"`.

Signed-off-by: blam <ben@blam.sh>
@github-actions github-actions bot added the microsite Changes to backstage.io label Apr 27, 2023
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
Signed-off-by: blam <ben@blam.sh>
markdown: {
preprocessor({ filePath, fileContent }) {
// Replace all HTML comments with emtpy strings as these are not supported by MDXv2.
return fileContent.replace(/<!--.*?-->/gs, '');

Check failure

Code scanning / CodeQL

Incomplete multi-character sanitization High

This string may still contain
<!--
, which may cause an HTML element injection vulnerability.
Copy link
Member

Choose a reason for hiding this comment

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

Nice, is this perhaps a replacement for scripts/pre-build.js ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep - now html docs are not supported anywhere, so I just strip them everywhere rather than just the API docs. But we can of course still write comments where needed, as we do have some examples where we need them.

Copy link
Member

Choose a reason for hiding this comment

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

Love it

@benjdlambert benjdlambert merged commit c8c6494 into master Apr 28, 2023
27 checks passed
@benjdlambert benjdlambert deleted the blam/fix-microsite-build branch April 28, 2023 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
microsite Changes to backstage.io
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants