-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
RFC: plugin Markdown lifecycles – configureMarkdownLoader #6370
Comments
The shiki-twoslash preset uses a mutating |
I've closed #6261 because parsing titles and descriptions seems to sacrifice too much performance. Interlinking pages with Markdown paths is still a problem and we have several tests that currently have incorrect outputs. With this proposal, we will be able to move this logic to the MDX loader and thus be able to work on an already parsed MDAST instead of raw strings. |
Fix all markdown links and configure the Docusaurus build to fail on broken links. Compared to before there are two main differences for links within Docusuaurus: * Links between URL links need to be URL links to be resolved. This will be fixed in Docusaurus 3 [1]. * Links that point to files outside the "docusaurus" directory need to be absolute links to be resolvable in the final website. This could mabye be improved by adding support for variables [2]. [1]: facebook/docusaurus#6370 [2]: facebook/docusaurus#395 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
Fix all Markdown links and configure the Docusaurus build to fail on broken links. Compared to before there are two main differences for links within Docusuaurus: * Links between URL links need to be URL links to be resolved. This will be fixed in Docusaurus 3 [1]. * Links that point to files outside the "docusaurus" directory need to be absolute links to be resolvable in the final website. This could mabye be improved by adding support for variables [2]. [1]: facebook/docusaurus#6370 [2]: facebook/docusaurus#395 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
Fix all Markdown links and configure the Docusaurus build to fail on broken links. Compared to before there are two main differences for links within Docusuaurus: * Links between URL links need to be URL links to be resolved. This will be fixed in Docusaurus 3 [1]. * Links that point to files outside the "docusaurus" directory need to be absolute links to be resolvable in the final website. This could mabye be improved by adding support for variables [2]. [1]: facebook/docusaurus#6370 [2]: facebook/docusaurus#395 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
In Docusaurus 2 links between different plugin instances need to be URL links which can only be resolved within the built website, but not in the raw files. Note that this is supposed to be fixed in Docusaurus 3 [1]. [1]: facebook/docusaurus#6370 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
Fix all Markdown links and configure the Docusaurus build to fail on broken links. Compared to before there are two main differences for links within Docusuaurus: * Links between URL links need to be URL links to be resolved. This will be fixed in Docusaurus 3 [1]. * Links that point to files outside the "docusaurus" directory need to be absolute links to be resolvable in the final website. This could mabye be improved by adding support for variables [2]. [1]: facebook/docusaurus#6370 [2]: facebook/docusaurus#395 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
In Docusaurus 2 links between different plugin instances need to be URL links which can only be resolved within the built website, but not in the raw files. Note that this is supposed to be fixed in Docusaurus 3 [1]. [1]: facebook/docusaurus#6370 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
Fix all Markdown links and configure the Docusaurus build to fail on broken links. Compared to before there are two main differences for links within Docusuaurus: * Links between URL links need to be URL links to be resolved. This will be fixed in Docusaurus 3 [1]. * Links that point to files outside the "docusaurus" directory need to be absolute links to be resolvable in the final website. This could mabye be improved by adding support for variables [2]. [1]: facebook/docusaurus#6370 [2]: facebook/docusaurus#395 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
In Docusaurus 2 links between different plugin instances need to be URL links which can only be resolved within the built website, but not in the raw files. Note that this is supposed to be fixed in Docusaurus 3 [1]. [1]: facebook/docusaurus#6370 Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.io>
Have you read the Contributing Guidelines on issues?
Motivation
A more solid proposal derived from #4625. I propose two Markdown-related lifecycles for plugins:
configureMarkdownLoader
and.getMarkdownComponents
configureMarkdownLoader
Status quo
Currently, every content plugin uses
@docusaurus/mdx-loader
and passes it throughconfigureWebpack
. The docs and blog plugins also host their own Markdown loaders, in order to access the file path -> URL mapping and convert MD links to URL links.However, this means each plugin's data is completely sandboxed, all the way from content loading to route creation. A plugin can't access routes created by another plugin at any stage in its lifespan. In addition, this means duplicated logic in every plugin. After #5999, the remark plugins will be moved to a global config option, which has to be hooked into in every plugin.
This also means that linkification happens before any Remark plugin gets loaded, and people can't remap Markdown paths, as requested in #4039, because when the
beforeDefaultRemarkPlugins
get loaded, the Markdown links don't exist any more.Resolution
I propose that we move the MDX loader to the core, just like the CSS loader or JS loader. This effectively means we treat MD as a first-class citizen in our architecture. And then, each plugin will pass in loader options that are aggregated together. This solves several problems:
filePathToPermalink
map.For example:
The only problem is that some logic is ultimately plugin-specific. For example, how do we handle file-specific logic if the file queried is not handled by this plugin? My current solution is an
isIncluded
function. All configs are aggregated in a list, and for each file, theisIncluded
callback is first called. If it returnstrue
, then the rest of the callbacks are executed. All callbacks are called withfilePath
, but maybe we can also pass infileContent
if there's a use?`getMarkdownComponents` is now unnecessary
getMarkdownComponents
Status quo
Currently, the classic theme registers global Markdown components through the
MDXComponents
. This is problematic, because other themes can't register components on top of this unless we solve #4530. Moreover, the API surface is very implicit to the user. This is ultimately just a register, not a component, and can't be wrapped like other components. (Although you can still use object spreading)Resolution
I propose a new
getMarkdownComponents
that's likegetThemePath
. It returns a path to a component map, in the same shape as the currentMDXComponents
. The core would merge all component registers and generate it as a temp file. Anything that uses theMDXProvider
just needs to import from the generated folder.After some more thoughts, I don't think we need the
getMarkdownComponents
API. Instead, we will solve #4530, and allow each theme to wrap the previous one'sMDXComponents
(which I'm also considering to be refactored into auseMDXGlobals
hook).Self-service
The text was updated successfully, but these errors were encountered: