Skip to content

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 }}"`.

@benjdlambert benjdlambert requested review from a team and backstage-service as code owners April 27, 2023 17:58
@benjdlambert benjdlambert requested a review from freben April 27, 2023 17:58
@github-actions github-actions bot added the area:microsite Changes to backstage.io label Apr 27, 2023
@benjdlambert benjdlambert force-pushed the blam/fix-microsite-build branch from 5b4aada to 79edc8e Compare April 27, 2023 18:44
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

This string may still contain [<!--](1), 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
@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

area:microsite Changes to backstage.io

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants