From 3697f954ffe5b882804b79172dd94cfc726ab55e Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 14:20:32 +0100 Subject: [PATCH 01/24] add more parseURLPath unit tests --- .../src/__tests__/urlUtils.test.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/docusaurus-utils/src/__tests__/urlUtils.test.ts b/packages/docusaurus-utils/src/__tests__/urlUtils.test.ts index 301a91ae3224..7ed1cbbf9cea 100644 --- a/packages/docusaurus-utils/src/__tests__/urlUtils.test.ts +++ b/packages/docusaurus-utils/src/__tests__/urlUtils.test.ts @@ -301,6 +301,29 @@ describe('parseURLPath', () => { }); }); + it('parse anchor', () => { + expect(parseURLPath('#anchor')).toEqual({ + pathname: '/', + search: undefined, + hash: 'anchor', + }); + expect(parseURLPath('#anchor', '/page')).toEqual({ + pathname: '/page', + search: undefined, + hash: 'anchor', + }); + expect(parseURLPath('#')).toEqual({ + pathname: '/', + search: undefined, + hash: '', + }); + expect(parseURLPath('#', '/page')).toEqual({ + pathname: '/page', + search: undefined, + hash: '', + }); + }); + it('parse hash', () => { expect(parseURLPath('/page')).toEqual({ pathname: '/page', From 194642d786652532fc8d04e86fb01616a34e0c18 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 14:31:48 +0100 Subject: [PATCH 02/24] add try/catch/cause to improve troubleshooting in case of getBrokenLinksForPage() failure --- packages/docusaurus/src/server/brokenLinks.ts | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index ccbaadcd3ffb..da6e354ca506 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -117,15 +117,21 @@ function getBrokenLinks({ }): BrokenLinksMap { const filteredRoutes = filterIntermediateRoutes(routes); - return _.mapValues(collectedLinks, (pageCollectedData, pagePath) => - getBrokenLinksForPage({ - collectedLinks, - pageLinks: pageCollectedData.links, - pageAnchors: pageCollectedData.anchors, - pagePath, - routes: filteredRoutes, - }), - ); + return _.mapValues(collectedLinks, (pageCollectedData, pagePath) => { + try { + return getBrokenLinksForPage({ + collectedLinks, + pageLinks: pageCollectedData.links, + pageAnchors: pageCollectedData.anchors, + pagePath, + routes: filteredRoutes, + }); + } catch (e) { + throw new Error(`Unable to get broken links for page ${pagePath}.`, { + cause: e, + }); + } + }); } function brokenLinkMessage(brokenLink: BrokenLink): string { From 4cb761bb4d225471a2e48704e76e27b091b794e7 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 17:24:36 +0100 Subject: [PATCH 03/24] DropdownNavbarItem should not check for broken links on # anchors --- .../src/theme/NavbarItem/DropdownNavbarItem/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx index fc1d8d356048..523af5cbf957 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx @@ -89,7 +89,12 @@ function DropdownNavbarItemDesktop({ aria-haspopup="true" aria-expanded={showDropdown} role="button" - href={props.to ? undefined : '#'} + {...(props.to + ? undefined + : // Permits to make the tag focusable in case no link target + // See https://github.com/facebook/docusaurus/pull/6003 + // There's probably a better solution though... + {href: '#', 'data-noBrokenLinkCheck': true})} className={clsx('navbar__link', className)} {...props} onClick={props.to ? undefined : (e) => e.preventDefault()} From 30b7852056bb54dd366c9a10f50e06878b1d28df Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 17:26:21 +0100 Subject: [PATCH 04/24] add broken anchors test page --- .../_docs tests/tests/links/broken-anchors-tests.mdx | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 website/_dogfooding/_docs tests/tests/links/broken-anchors-tests.mdx diff --git a/website/_dogfooding/_docs tests/tests/links/broken-anchors-tests.mdx b/website/_dogfooding/_docs tests/tests/links/broken-anchors-tests.mdx new file mode 100644 index 000000000000..dbc3c790b763 --- /dev/null +++ b/website/_dogfooding/_docs tests/tests/links/broken-anchors-tests.mdx @@ -0,0 +1,9 @@ +# Broken Anchors tests + +import Link from '@docusaurus/Link'; + +#test-link-anchor + +[Markdown link to above anchor](#test-link-anchor) + +[Markdown link to above anchor](#) From 4070bfc34f0be0ba5dcd3c96ca2ba9258ce92ecc Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 17:27:13 +0100 Subject: [PATCH 05/24] Link should report anchors links to the broken links checker --- packages/docusaurus/src/client/exports/Link.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/src/client/exports/Link.tsx b/packages/docusaurus/src/client/exports/Link.tsx index 8b886c8e7073..427c24b79af0 100644 --- a/packages/docusaurus/src/client/exports/Link.tsx +++ b/packages/docusaurus/src/client/exports/Link.tsx @@ -140,10 +140,13 @@ function Link( }; }, [ioRef, targetLink, IOSupported, isInternal]); + // It is simple local anchor link targeting current page? const isAnchorLink = targetLink?.startsWith('#') ?? false; + + // Should we use a regular tag instead of React-Router Link component? const isRegularHtmlLink = !targetLink || !isInternal || isAnchorLink; - if (!isRegularHtmlLink && !noBrokenLinkCheck) { + if (!noBrokenLinkCheck && (isAnchorLink || !isRegularHtmlLink)) { brokenLinks.collectLink(targetLink!); } From 6dbc6dc196853f6b3483bf02a8c3919eb9b26683 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 17:43:17 +0100 Subject: [PATCH 06/24] fix #wrapping anchor link --- website/docs/advanced/client.mdx | 2 +- website/versioned_docs/version-2.x/advanced/client.mdx | 2 +- website/versioned_docs/version-3.0.1/advanced/client.mdx | 2 +- website/versioned_docs/version-3.1.0/advanced/client.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/advanced/client.mdx b/website/docs/advanced/client.mdx index dd77268610f3..f4d37d296ded 100644 --- a/website/docs/advanced/client.mdx +++ b/website/docs/advanced/client.mdx @@ -33,7 +33,7 @@ website `website/src/theme/Navbar.js` takes precedence whenever `@theme/Navbar` is imported. This behavior is called component swizzling. If you are familiar with Objective C where a function's implementation can be swapped during runtime, it's the exact same concept here with changing the target `@theme/Navbar` is pointing to! -We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. +We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](../swizzling.mdx#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. Here's an example of using this feature to enhance the default theme `CodeBlock` component with a `react-live` playground feature. diff --git a/website/versioned_docs/version-2.x/advanced/client.mdx b/website/versioned_docs/version-2.x/advanced/client.mdx index 6a01e76346da..9f29c0ca2e53 100644 --- a/website/versioned_docs/version-2.x/advanced/client.mdx +++ b/website/versioned_docs/version-2.x/advanced/client.mdx @@ -33,7 +33,7 @@ website `website/src/theme/Navbar.js` takes precedence whenever `@theme/Navbar` is imported. This behavior is called component swizzling. If you are familiar with Objective C where a function's implementation can be swapped during runtime, it's the exact same concept here with changing the target `@theme/Navbar` is pointing to! -We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. +We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](../swizzling.mdx#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. Here's an example of using this feature to enhance the default theme `CodeBlock` component with a `react-live` playground feature. diff --git a/website/versioned_docs/version-3.0.1/advanced/client.mdx b/website/versioned_docs/version-3.0.1/advanced/client.mdx index dd77268610f3..f4d37d296ded 100644 --- a/website/versioned_docs/version-3.0.1/advanced/client.mdx +++ b/website/versioned_docs/version-3.0.1/advanced/client.mdx @@ -33,7 +33,7 @@ website `website/src/theme/Navbar.js` takes precedence whenever `@theme/Navbar` is imported. This behavior is called component swizzling. If you are familiar with Objective C where a function's implementation can be swapped during runtime, it's the exact same concept here with changing the target `@theme/Navbar` is pointing to! -We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. +We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](../swizzling.mdx#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. Here's an example of using this feature to enhance the default theme `CodeBlock` component with a `react-live` playground feature. diff --git a/website/versioned_docs/version-3.1.0/advanced/client.mdx b/website/versioned_docs/version-3.1.0/advanced/client.mdx index dd77268610f3..f4d37d296ded 100644 --- a/website/versioned_docs/version-3.1.0/advanced/client.mdx +++ b/website/versioned_docs/version-3.1.0/advanced/client.mdx @@ -33,7 +33,7 @@ website `website/src/theme/Navbar.js` takes precedence whenever `@theme/Navbar` is imported. This behavior is called component swizzling. If you are familiar with Objective C where a function's implementation can be swapped during runtime, it's the exact same concept here with changing the target `@theme/Navbar` is pointing to! -We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. +We already talked about how the "userland theme" in `src/theme` can re-use a theme component through the [`@theme-original`](../swizzling.mdx#wrapping) alias. One theme package can also wrap a component from another theme, by importing the component from the initial theme, using the `@theme-init` import. Here's an example of using this feature to enhance the default theme `CodeBlock` component with a `react-live` playground feature. From 1cb85f489730ba97fdbfbce7d8f0ce5cc318eadf Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 17:43:27 +0100 Subject: [PATCH 07/24] fix migration anchor link --- website/blog/2021-11-21-algolia-docsearch-migration/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx b/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx index 583054e5410b..82866a5c50b5 100644 --- a/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx +++ b/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx @@ -92,7 +92,7 @@ And of course, **a lot more, for free**. ## FAQ -### I'm using Docusaurus and DocSearch, can I migrate? +### I'm using Docusaurus and DocSearch, can I migrate? {#im-using-docusaurus-and-docsearch-can-i-migrate} At the time we are writing this, we are still at an early stage of the migration. We are doing small batches every week but will increase the load shortly, so please be patient and keep an eye out in your mailbox, you'll be contacted as soon as your Algolia app is ready! From f1dd8c11e50001b2d57ca58e12b7f20ca92f7d5c Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 17:51:24 +0100 Subject: [PATCH 08/24] fix preset options anchor links --- website/docs/api/plugins/plugin-content-blog.mdx | 2 +- website/docs/api/plugins/plugin-content-docs.mdx | 2 +- website/docs/api/plugins/plugin-content-pages.mdx | 2 +- website/docs/api/plugins/plugin-debug.mdx | 2 +- website/docs/api/plugins/plugin-google-analytics.mdx | 2 +- website/docs/api/plugins/plugin-google-gtag.mdx | 2 +- website/docs/api/plugins/plugin-google-tag-manager.mdx | 2 +- website/docs/api/plugins/plugin-sitemap.mdx | 2 +- .../version-2.x/api/plugins/plugin-content-blog.mdx | 2 +- .../version-2.x/api/plugins/plugin-content-docs.mdx | 2 +- .../version-2.x/api/plugins/plugin-content-pages.mdx | 2 +- website/versioned_docs/version-2.x/api/plugins/plugin-debug.mdx | 2 +- .../version-2.x/api/plugins/plugin-google-analytics.mdx | 2 +- .../version-2.x/api/plugins/plugin-google-gtag.mdx | 2 +- .../version-2.x/api/plugins/plugin-google-tag-manager.mdx | 2 +- .../versioned_docs/version-2.x/api/plugins/plugin-sitemap.mdx | 2 +- .../version-3.0.1/api/plugins/plugin-content-blog.mdx | 2 +- .../version-3.0.1/api/plugins/plugin-content-docs.mdx | 2 +- .../version-3.0.1/api/plugins/plugin-content-pages.mdx | 2 +- .../versioned_docs/version-3.0.1/api/plugins/plugin-debug.mdx | 2 +- .../version-3.0.1/api/plugins/plugin-google-analytics.mdx | 2 +- .../version-3.0.1/api/plugins/plugin-google-gtag.mdx | 2 +- .../version-3.0.1/api/plugins/plugin-google-tag-manager.mdx | 2 +- .../versioned_docs/version-3.0.1/api/plugins/plugin-sitemap.mdx | 2 +- .../version-3.1.0/api/plugins/plugin-content-blog.mdx | 2 +- .../version-3.1.0/api/plugins/plugin-content-docs.mdx | 2 +- .../version-3.1.0/api/plugins/plugin-content-pages.mdx | 2 +- .../versioned_docs/version-3.1.0/api/plugins/plugin-debug.mdx | 2 +- .../version-3.1.0/api/plugins/plugin-google-analytics.mdx | 2 +- .../version-3.1.0/api/plugins/plugin-google-gtag.mdx | 2 +- .../version-3.1.0/api/plugins/plugin-google-tag-manager.mdx | 2 +- .../versioned_docs/version-3.1.0/api/plugins/plugin-sitemap.mdx | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/website/docs/api/plugins/plugin-content-blog.mdx b/website/docs/api/plugins/plugin-content-blog.mdx index 06d896da5faa..41a90b4058ab 100644 --- a/website/docs/api/plugins/plugin-content-blog.mdx +++ b/website/docs/api/plugins/plugin-content-blog.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-content-blog If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-content-docs.mdx b/website/docs/api/plugins/plugin-content-docs.mdx index b0fa4907c48b..7730d8fe468d 100644 --- a/website/docs/api/plugins/plugin-content-docs.mdx +++ b/website/docs/api/plugins/plugin-content-docs.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-docs If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-content-pages.mdx b/website/docs/api/plugins/plugin-content-pages.mdx index 7dcb84a82213..8894e7861b4c 100644 --- a/website/docs/api/plugins/plugin-content-pages.mdx +++ b/website/docs/api/plugins/plugin-content-pages.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-pages If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-debug.mdx b/website/docs/api/plugins/plugin-debug.mdx index cd37b1f0834a..e580466ce5b0 100644 --- a/website/docs/api/plugins/plugin-debug.mdx +++ b/website/docs/api/plugins/plugin-debug.mdx @@ -49,7 +49,7 @@ npm install --save @docusaurus/plugin-debug If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-google-analytics.mdx b/website/docs/api/plugins/plugin-google-analytics.mdx index 555e5bea7277..45d5189b4810 100644 --- a/website/docs/api/plugins/plugin-google-analytics.mdx +++ b/website/docs/api/plugins/plugin-google-analytics.mdx @@ -35,7 +35,7 @@ npm install --save @docusaurus/plugin-google-analytics If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-google-gtag.mdx b/website/docs/api/plugins/plugin-google-gtag.mdx index 501b6c2f42c8..16fab6fbd270 100644 --- a/website/docs/api/plugins/plugin-google-gtag.mdx +++ b/website/docs/api/plugins/plugin-google-gtag.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-gtag If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-google-tag-manager.mdx b/website/docs/api/plugins/plugin-google-tag-manager.mdx index 43182aec075d..e444a5387760 100644 --- a/website/docs/api/plugins/plugin-google-tag-manager.mdx +++ b/website/docs/api/plugins/plugin-google-tag-manager.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-tag-manager If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/docs/api/plugins/plugin-sitemap.mdx b/website/docs/api/plugins/plugin-sitemap.mdx index 0d6b72763c03..29832b4ddb21 100644 --- a/website/docs/api/plugins/plugin-sitemap.mdx +++ b/website/docs/api/plugins/plugin-sitemap.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-sitemap If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-content-blog.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-content-blog.mdx index 8afee91793bc..96f4abb48f59 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-content-blog.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-content-blog.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-content-blog If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-content-docs.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-content-docs.mdx index cd98d4e99e1c..e350e9a308de 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-content-docs.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-content-docs.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-docs If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-content-pages.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-content-pages.mdx index 1231c981304f..cb38e77966b5 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-content-pages.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-content-pages.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-pages If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-debug.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-debug.mdx index 7cbbdcbe94a2..f5fce235bdd2 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-debug.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-debug.mdx @@ -49,7 +49,7 @@ npm install --save @docusaurus/plugin-debug If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-google-analytics.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-google-analytics.mdx index 555e5bea7277..45d5189b4810 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-google-analytics.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-google-analytics.mdx @@ -35,7 +35,7 @@ npm install --save @docusaurus/plugin-google-analytics If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-google-gtag.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-google-gtag.mdx index 501b6c2f42c8..16fab6fbd270 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-google-gtag.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-google-gtag.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-gtag If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-google-tag-manager.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-google-tag-manager.mdx index e1b1589db6ad..e6c2c1c2fe66 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-google-tag-manager.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-google-tag-manager.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-tag-manager If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-2.x/api/plugins/plugin-sitemap.mdx b/website/versioned_docs/version-2.x/api/plugins/plugin-sitemap.mdx index 0d6b72763c03..29832b4ddb21 100644 --- a/website/versioned_docs/version-2.x/api/plugins/plugin-sitemap.mdx +++ b/website/versioned_docs/version-2.x/api/plugins/plugin-sitemap.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-sitemap If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-blog.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-blog.mdx index 54d9b340a4a0..bacdb23519a7 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-blog.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-blog.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-content-blog If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-docs.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-docs.mdx index 754a56d293d9..6427ff88c830 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-docs.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-docs.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-docs If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-pages.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-pages.mdx index ee9ff06016e1..b115eac1dccb 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-pages.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-content-pages.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-pages If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-debug.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-debug.mdx index cd37b1f0834a..e580466ce5b0 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-debug.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-debug.mdx @@ -49,7 +49,7 @@ npm install --save @docusaurus/plugin-debug If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-analytics.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-analytics.mdx index 555e5bea7277..45d5189b4810 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-analytics.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-analytics.mdx @@ -35,7 +35,7 @@ npm install --save @docusaurus/plugin-google-analytics If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-gtag.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-gtag.mdx index 501b6c2f42c8..16fab6fbd270 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-gtag.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-gtag.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-gtag If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-tag-manager.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-tag-manager.mdx index 43182aec075d..e444a5387760 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-tag-manager.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-google-tag-manager.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-tag-manager If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.0.1/api/plugins/plugin-sitemap.mdx b/website/versioned_docs/version-3.0.1/api/plugins/plugin-sitemap.mdx index 0d6b72763c03..29832b4ddb21 100644 --- a/website/versioned_docs/version-3.0.1/api/plugins/plugin-sitemap.mdx +++ b/website/versioned_docs/version-3.0.1/api/plugins/plugin-sitemap.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-sitemap If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-blog.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-blog.mdx index 54d9b340a4a0..bacdb23519a7 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-blog.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-blog.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-content-blog If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-docs.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-docs.mdx index 754a56d293d9..6427ff88c830 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-docs.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-docs.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-docs If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-pages.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-pages.mdx index ee9ff06016e1..b115eac1dccb 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-pages.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-content-pages.mdx @@ -19,7 +19,7 @@ npm install --save @docusaurus/plugin-content-pages If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-debug.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-debug.mdx index cd37b1f0834a..e580466ce5b0 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-debug.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-debug.mdx @@ -49,7 +49,7 @@ npm install --save @docusaurus/plugin-debug If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-analytics.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-analytics.mdx index 555e5bea7277..45d5189b4810 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-analytics.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-analytics.mdx @@ -35,7 +35,7 @@ npm install --save @docusaurus/plugin-google-analytics If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-gtag.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-gtag.mdx index 501b6c2f42c8..16fab6fbd270 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-gtag.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-gtag.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-gtag If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-tag-manager.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-tag-manager.mdx index 43182aec075d..e444a5387760 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-tag-manager.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-google-tag-manager.mdx @@ -31,7 +31,7 @@ npm install --save @docusaurus/plugin-google-tag-manager If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the preset options. +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: diff --git a/website/versioned_docs/version-3.1.0/api/plugins/plugin-sitemap.mdx b/website/versioned_docs/version-3.1.0/api/plugins/plugin-sitemap.mdx index 0d6b72763c03..29832b4ddb21 100644 --- a/website/versioned_docs/version-3.1.0/api/plugins/plugin-sitemap.mdx +++ b/website/versioned_docs/version-3.1.0/api/plugins/plugin-sitemap.mdx @@ -25,7 +25,7 @@ npm install --save @docusaurus/plugin-sitemap If you use the preset `@docusaurus/preset-classic`, you don't need to install this plugin as a dependency. -You can configure this plugin through the [preset options](#ex-config-preset). +You can configure this plugin through the [preset options](../../using-plugins.mdx#docusauruspreset-classic). ::: From fddce81998ac02e954107de0765e515827236737 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 18:01:32 +0100 Subject: [PATCH 09/24] fix migration-automated.mdx broken anchors --- website/docs/migration/v2/migration-automated.mdx | 2 +- .../version-2.x/migration/migration-automated.mdx | 2 +- .../version-3.0.1/migration/v2/migration-automated.mdx | 2 +- .../version-3.1.0/migration/v2/migration-automated.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/migration/v2/migration-automated.mdx b/website/docs/migration/v2/migration-automated.mdx index 61e07cc4c1f5..ff4139d2e71d 100644 --- a/website/docs/migration/v2/migration-automated.mdx +++ b/website/docs/migration/v2/migration-automated.mdx @@ -24,7 +24,7 @@ The migration CLI migrates: To use the migration CLI, follow these steps: -1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the [structure](#) shown at the start of this page. +1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the expected structure. 2. To migrate your v1 website, run the migration CLI with the appropriate filesystem paths: diff --git a/website/versioned_docs/version-2.x/migration/migration-automated.mdx b/website/versioned_docs/version-2.x/migration/migration-automated.mdx index 93c41ae8863f..efb7e018f9f3 100644 --- a/website/versioned_docs/version-2.x/migration/migration-automated.mdx +++ b/website/versioned_docs/version-2.x/migration/migration-automated.mdx @@ -24,7 +24,7 @@ The migration CLI migrates: To use the migration CLI, follow these steps: -1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the [structure](#) shown at the start of this page. +1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the expected structure. 2. To migrate your v1 website, run the migration CLI with the appropriate filesystem paths: diff --git a/website/versioned_docs/version-3.0.1/migration/v2/migration-automated.mdx b/website/versioned_docs/version-3.0.1/migration/v2/migration-automated.mdx index 61e07cc4c1f5..ff4139d2e71d 100644 --- a/website/versioned_docs/version-3.0.1/migration/v2/migration-automated.mdx +++ b/website/versioned_docs/version-3.0.1/migration/v2/migration-automated.mdx @@ -24,7 +24,7 @@ The migration CLI migrates: To use the migration CLI, follow these steps: -1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the [structure](#) shown at the start of this page. +1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the expected structure. 2. To migrate your v1 website, run the migration CLI with the appropriate filesystem paths: diff --git a/website/versioned_docs/version-3.1.0/migration/v2/migration-automated.mdx b/website/versioned_docs/version-3.1.0/migration/v2/migration-automated.mdx index 61e07cc4c1f5..ff4139d2e71d 100644 --- a/website/versioned_docs/version-3.1.0/migration/v2/migration-automated.mdx +++ b/website/versioned_docs/version-3.1.0/migration/v2/migration-automated.mdx @@ -24,7 +24,7 @@ The migration CLI migrates: To use the migration CLI, follow these steps: -1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the [structure](#) shown at the start of this page. +1. Before using the migration CLI, ensure that `/docs`, `/blog`, `/static`, `sidebars.json`, `siteConfig.js`, `package.json` follow the expected structure. 2. To migrate your v1 website, run the migration CLI with the appropriate filesystem paths: From dae7c8d18db499f2c46ea020aeedd6e092338aca Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 18:02:24 +0100 Subject: [PATCH 10/24] APITable should collectAnchor ids --- website/src/components/APITable/index.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/src/components/APITable/index.tsx b/website/src/components/APITable/index.tsx index 049e2d4bcfd4..29e9890bea46 100644 --- a/website/src/components/APITable/index.tsx +++ b/website/src/components/APITable/index.tsx @@ -13,6 +13,7 @@ import React, { useRef, useEffect, } from 'react'; +import useBrokenLinks from '@docusaurus/useBrokenLinks'; import {useHistory} from '@docusaurus/router'; import styles from './styles.module.css'; @@ -41,6 +42,7 @@ function APITableRow( const id = name ? `${name}-${entryName}` : entryName; const anchor = `#${id}`; const history = useHistory(); + useBrokenLinks().collectAnchor(id); return ( Date: Thu, 11 Jan 2024 18:05:27 +0100 Subject: [PATCH 11/24] fix autogenerated link --- website/docs/guides/docs/sidebar/items.mdx | 2 +- .../versioned_docs/version-2.x/guides/docs/sidebar/items.mdx | 2 +- .../versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx | 2 +- .../versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/guides/docs/sidebar/items.mdx b/website/docs/guides/docs/sidebar/items.mdx index 8b2ac4e764e2..baf7f14c5b6c 100644 --- a/website/docs/guides/docs/sidebar/items.mdx +++ b/website/docs/guides/docs/sidebar/items.mdx @@ -61,7 +61,7 @@ export default { }; ``` -If you use the doc shorthand or [autogenerated](#sidebar-item-autogenerated) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. +If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. :::note diff --git a/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx b/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx index 77789ebf474c..21a6e92aa65e 100644 --- a/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx +++ b/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx @@ -61,7 +61,7 @@ module.exports = { }; ``` -If you use the doc shorthand or [autogenerated](#sidebar-item-autogenerated) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. +If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. :::note diff --git a/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx b/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx index 8b2ac4e764e2..baf7f14c5b6c 100644 --- a/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx +++ b/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx @@ -61,7 +61,7 @@ export default { }; ``` -If you use the doc shorthand or [autogenerated](#sidebar-item-autogenerated) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. +If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. :::note diff --git a/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx b/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx index 8b2ac4e764e2..baf7f14c5b6c 100644 --- a/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx +++ b/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx @@ -61,7 +61,7 @@ export default { }; ``` -If you use the doc shorthand or [autogenerated](#sidebar-item-autogenerated) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. +If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the `sidebar_label` Markdown front matter within that doc, which has higher precedence over the `label` key in the sidebar item. Similarly, you can use `sidebar_custom_props` to declare custom metadata for a doc page. :::note From ac34d64bbffe19847974e1ffc9e7a3cc0687e477 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 18:07:14 +0100 Subject: [PATCH 12/24] fix #sidebar-association anchor link --- website/docs/guides/docs/sidebar/items.mdx | 2 +- .../versioned_docs/version-2.x/guides/docs/sidebar/items.mdx | 2 +- .../versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx | 2 +- .../versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/guides/docs/sidebar/items.mdx b/website/docs/guides/docs/sidebar/items.mdx index baf7f14c5b6c..1dd0c0100e78 100644 --- a/website/docs/guides/docs/sidebar/items.mdx +++ b/website/docs/guides/docs/sidebar/items.mdx @@ -65,7 +65,7 @@ If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you :::note -A `doc` item sets an [implicit sidebar association](#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. +A `doc` item sets an [implicit sidebar association](./multiple-sidebars.mdx#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. ::: diff --git a/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx b/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx index 21a6e92aa65e..fb7e0538c9e5 100644 --- a/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx +++ b/website/versioned_docs/version-2.x/guides/docs/sidebar/items.mdx @@ -65,7 +65,7 @@ If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you :::note -A `doc` item sets an [implicit sidebar association](#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. +A `doc` item sets an [implicit sidebar association](./multiple-sidebars.mdx#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. ::: diff --git a/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx b/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx index baf7f14c5b6c..1dd0c0100e78 100644 --- a/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx +++ b/website/versioned_docs/version-3.0.1/guides/docs/sidebar/items.mdx @@ -65,7 +65,7 @@ If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you :::note -A `doc` item sets an [implicit sidebar association](#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. +A `doc` item sets an [implicit sidebar association](./multiple-sidebars.mdx#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. ::: diff --git a/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx b/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx index baf7f14c5b6c..1dd0c0100e78 100644 --- a/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx +++ b/website/versioned_docs/version-3.1.0/guides/docs/sidebar/items.mdx @@ -65,7 +65,7 @@ If you use the doc shorthand or [autogenerated](autogenerated.mdx) sidebar, you :::note -A `doc` item sets an [implicit sidebar association](#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. +A `doc` item sets an [implicit sidebar association](./multiple-sidebars.mdx#sidebar-association). Don't assign the same doc to multiple sidebars: change the type to `ref` instead. ::: From d244b0da91ce14b8e5f2382e669ead3014b8d5be Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 18:20:13 +0100 Subject: [PATCH 13/24] Broken link checker should accept empty anchors --- .../src/server/__tests__/brokenLinks.test.ts | 46 ++++++++++--------- packages/docusaurus/src/server/brokenLinks.ts | 7 +++ 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts index 158af9165af7..a30aae384426 100644 --- a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts +++ b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts @@ -140,6 +140,30 @@ describe('handleBrokenLinks', () => { }); }); + it('accepts valid link with empty anchor', async () => { + await testBrokenLinks({ + routes: [{path: '/page 1'}, {path: '/page 2'}], + collectedLinks: { + '/page 1': { + links: [ + '/page 1', + '/page 2', + '/page 1#', + '/page 2#', + '/page 1?age=42#', + '/page 2?age=42#', + '#', + '#', + './page 1#', + './page 2#', + ], + anchors: [], + }, + '/page 2': {links: [], anchors: []}, + }, + }); + }); + it('rejects broken link', async () => { await expect(() => testBrokenLinks({ @@ -225,28 +249,6 @@ describe('handleBrokenLinks', () => { `); }); - it('rejects valid link with empty broken anchor', async () => { - await expect(() => - testBrokenLinks({ - routes: [{path: '/page1'}, {path: '/page2'}], - collectedLinks: { - '/page1': {links: ['/page2#'], anchors: []}, - '/page2': {links: [], anchors: []}, - }, - }), - ).rejects.toThrowErrorMatchingInlineSnapshot(` - "Docusaurus found broken anchors! - - Please check the pages of your site in the list below, and make sure you don't reference any anchor that does not exist. - Note: it's possible to ignore broken anchors with the 'onBrokenAnchors' Docusaurus configuration, and let the build pass. - - Exhaustive list of all broken anchors found: - - Broken anchor on source page path = /page1: - -> linking to /page2# - " - `); - }); - it('rejects valid link with broken anchor + query-string', async () => { await expect(() => testBrokenLinks({ diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index da6e354ca506..092bc1551a25 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -57,6 +57,13 @@ function getBrokenLinksForPage({ return false; } + // Link has empty hash ("#", "/page#"...): we do not report it as broken + // Empty hashes are used for various weird reasons, by us and other users... + // See for example: https://github.com/facebook/docusaurus/pull/6003 + if (hash === '') { + return false; + } + const targetPage = collectedLinks[pathname] || collectedLinks[decodeURI(pathname)]; From eb1763f693467bf76168cbc67e15fc4ce56b9fa8 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 18:37:12 +0100 Subject: [PATCH 14/24] Broken link checker should accept empty hash links and unsafe/bad collected data --- .../src/server/__tests__/brokenLinks.test.ts | 46 +++++++++++++++++++ packages/docusaurus/src/server/brokenLinks.ts | 20 +++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts index a30aae384426..ff9fabbc46b9 100644 --- a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts +++ b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts @@ -86,6 +86,52 @@ describe('handleBrokenLinks', () => { }); }); + it('accepts valid link with anchor reported with hash prefix', async () => { + await testBrokenLinks({ + routes: [{path: '/page1'}, {path: '/page2'}], + collectedLinks: { + '/page1': {links: ['/page2#page2anchor'], anchors: []}, + '/page2': {links: [], anchors: ['#page2anchor']}, + }, + }); + }); + + it('accepts valid links and anchors, sparse arrays', async () => { + await testBrokenLinks({ + routes: [{path: '/page1'}, {path: '/page2'}], + collectedLinks: { + '/page1': { + links: [ + '/page1', + // @ts-expect-error: invalid type on purpose + undefined, + // @ts-expect-error: invalid type on purpose + null, + // @ts-expect-error: invalid type on purpose + 42, + '/page2', + '/page2#page2anchor1', + '/page2#page2anchor2', + ], + anchors: [], + }, + '/page2': { + links: [], + anchors: [ + 'page2anchor1', + // @ts-expect-error: invalid type on purpose + undefined, + // @ts-expect-error: invalid type on purpose + null, + // @ts-expect-error: invalid type on purpose + 42, + 'page2anchor2', + ], + }, + }, + }); + }); + it('accepts valid link with querystring + anchor', async () => { await testBrokenLinks({ routes: [{path: '/page1'}, {path: '/page2'}], diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index 092bc1551a25..9daade859127 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -290,6 +290,21 @@ function reportBrokenLinks({ } } +// Users might use the useBrokenLinks() API in weird unexpected ways +// JS users might call "collectLink(undefined)" for example +// TS users might call "collectAnchor('#hash')" with/without # +// We clean/normalize the collected data to avoid obscure errors being thrown +function normalizeCollectedLinks( + collectedLinks: CollectedLinks, +): CollectedLinks { + return _.mapValues(collectedLinks, (pageCollectedData) => ({ + links: pageCollectedData.links.filter(_.isString), + anchors: pageCollectedData.anchors + .filter(_.isString) + .map((anchor) => (anchor.startsWith('#') ? anchor.slice(1) : anchor)), + })); +} + export async function handleBrokenLinks({ collectedLinks, onBrokenLinks, @@ -304,6 +319,9 @@ export async function handleBrokenLinks({ if (onBrokenLinks === 'ignore' && onBrokenAnchors === 'ignore') { return; } - const brokenLinks = getBrokenLinks({routes, collectedLinks}); + const brokenLinks = getBrokenLinks({ + routes, + collectedLinks: normalizeCollectedLinks(collectedLinks), + }); reportBrokenLinks({brokenLinks, onBrokenLinks, onBrokenAnchors}); } From 7084ad4a06b8aacd40cdee4dd93630a0110d8405 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 18:38:22 +0100 Subject: [PATCH 15/24] revert DropdownNavbarItemDesktop change --- .../src/theme/NavbarItem/DropdownNavbarItem/index.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx index 523af5cbf957..7a99b6fb0a50 100644 --- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/DropdownNavbarItem/index.tsx @@ -89,12 +89,10 @@ function DropdownNavbarItemDesktop({ aria-haspopup="true" aria-expanded={showDropdown} role="button" - {...(props.to - ? undefined - : // Permits to make the tag focusable in case no link target - // See https://github.com/facebook/docusaurus/pull/6003 - // There's probably a better solution though... - {href: '#', 'data-noBrokenLinkCheck': true})} + // # hash permits to make the tag focusable in case no link target + // See https://github.com/facebook/docusaurus/pull/6003 + // There's probably a better solution though... + href={props.to ? undefined : '#'} className={clsx('navbar__link', className)} {...props} onClick={props.to ? undefined : (e) => e.preventDefault()} From 01dfbe9d196dabda87e6527c597d48408628414a Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 19:35:40 +0100 Subject: [PATCH 16/24] Relax broken link checker, let it accept any pathname that was collected This notably allows "#" link on the /404.html page --- .../src/server/__tests__/brokenLinks.test.ts | 19 +++++++++++++++++++ packages/docusaurus/src/server/brokenLinks.ts | 14 +++++++++++--- packages/docusaurus/src/server/routes.ts | 11 ++++++++++- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts index ff9fabbc46b9..f811cbd91fc5 100644 --- a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts +++ b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts @@ -132,6 +132,25 @@ describe('handleBrokenLinks', () => { }); }); + it('accepts valid link and anchor to collected pages that are not in routes', async () => { + // This tests the edge-case of the 404 page: + // We don't have a {path: '404.html'} route + // But yet we collect links/anchors to it and allow linking to it + await testBrokenLinks({ + routes: [], + collectedLinks: { + '/page 1': { + links: ['/page 2#anchor-page-2'], + anchors: ['anchor-page-1'], + }, + '/page 2': { + links: ['/page 1#anchor-page-1', '/page%201#anchor-page-1'], + anchors: ['anchor-page-2'], + }, + }, + }); + }); + it('accepts valid link with querystring + anchor', async () => { await testBrokenLinks({ routes: [{path: '/page1'}, {path: '/page2'}], diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index 9daade859127..19fc413b1838 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -38,15 +38,23 @@ function getBrokenLinksForPage({ pageAnchors: string[]; routes: RouteConfig[]; }): BrokenLink[] { - // console.log('routes:', routes); + const allCollectedPaths = new Set(Object.keys(collectedLinks)); + function isPathBrokenLink(linkPath: URLPath) { - const matchedRoutes = [linkPath.pathname, decodeURI(linkPath.pathname)] + const pathnames = [linkPath.pathname, decodeURI(linkPath.pathname)]; + const matchedRoutes = pathnames // @ts-expect-error: React router types RouteConfig with an actual React // component, but we load route components with string paths. // We don't actually access component here, so it's fine. .map((l) => matchRoutes(routes, l)) .flat(); - return matchedRoutes.length === 0; + // The link path is broken if: + // - it doesn't match any route + // - it doesn't match any collected path + return ( + matchedRoutes.length === 0 && + !pathnames.some((p) => allCollectedPaths.has(p)) + ); } function isAnchorBrokenLink(linkPath: URLPath) { diff --git a/packages/docusaurus/src/server/routes.ts b/packages/docusaurus/src/server/routes.ts index 6a63fa71ca73..907f77816b8f 100644 --- a/packages/docusaurus/src/server/routes.ts +++ b/packages/docusaurus/src/server/routes.ts @@ -276,6 +276,15 @@ ${JSON.stringify(routeConfig)}`, }); } +/** + * Old stuff + * As far as I understand, this is what permits to SSG the 404.html file + * This is rendered through the catch-all ComponentCreator("*") route + * Note CDNs only understand the 404.html file by convention + * The extension probably permits to avoid emitting "/404/index.html" + */ +const NotFoundRoutePath = '/404.html'; + /** * Routes are prepared into three temp files: * @@ -296,7 +305,7 @@ export function loadRoutes( routesConfig: '', routesChunkNames: {}, registry: {}, - routesPaths: [normalizeUrl([baseUrl, '404.html'])], + routesPaths: [normalizeUrl([baseUrl, NotFoundRoutePath])], }; // `genRouteCode` would mutate `res` From 58d7c4050316c928c53eb79b10799739ebc0e563 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 19:51:38 +0100 Subject: [PATCH 17/24] remove problematic anchor link, see bug reported https://github.com/facebook/docusaurus/issues/9731 --- website/blog/2021-11-21-algolia-docsearch-migration/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx b/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx index 82866a5c50b5..823f10a1659d 100644 --- a/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx +++ b/website/blog/2021-11-21-algolia-docsearch-migration/index.mdx @@ -14,7 +14,7 @@ image: ./img/social-card.png [DocSearch](https://docsearch.algolia.com/) is migrating to a new, more powerful system, which gives users their own Algolia application and new credentials. -Docusaurus site owners should upgrade their configuration with [their new credentials](#im-using-docusaurus-and-docsearch-can-i-migrate) **by February 1, 2022**, existing search indexes will be frozen and become read-only after this date. +Docusaurus site owners should upgrade their configuration with their new credentials **by February 1, 2022**, existing search indexes will be frozen and become read-only after this date. From 1ba0a883f805210587bf4841bbddaa34a78143b6 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 23:40:28 +0100 Subject: [PATCH 18/24] broken link checker should support hash uri encoding --- .../src/server/__tests__/brokenLinks.test.ts | 41 +++++++++++++++++++ packages/docusaurus/src/server/brokenLinks.ts | 4 +- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts index f811cbd91fc5..9f98a459f397 100644 --- a/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts +++ b/packages/docusaurus/src/server/__tests__/brokenLinks.test.ts @@ -197,10 +197,51 @@ describe('handleBrokenLinks', () => { '/page%202', '/page%202?age=42', '/page%202?age=42#page2anchor', + + '/some dir/page 3', + '/some dir/page 3#page3anchor', + '/some%20dir/page%203', + '/some%20dir/page%203#page3anchor', + '/some%20dir/page 3', + '/some dir/page%203', + '/some dir/page%203#page3anchor', ], anchors: [], }, '/page 2': {links: [], anchors: ['page2anchor']}, + '/some dir/page 3': {links: [], anchors: ['page3anchor']}, + }, + }); + }); + + it('accepts valid link with anchor with spaces and encoding', async () => { + await testBrokenLinks({ + routes: [{path: '/page 1'}, {path: '/page 2'}], + collectedLinks: { + '/page 1': { + links: [ + '/page 1#a b', + '#a b', + '#a%20b', + '#c d', + '#c%20d', + + '/page 2#你好', + '/page%202#你好', + '/page 2#%E4%BD%A0%E5%A5%BD', + '/page%202#%E4%BD%A0%E5%A5%BD', + + '/page 2#schrödingers-cat-principle', + '/page%202#schrödingers-cat-principle', + '/page 2#schr%C3%B6dingers-cat-principle', + '/page%202#schr%C3%B6dingers-cat-principle', + ], + anchors: ['a b', 'c%20d'], + }, + '/page 2': { + links: ['/page 1#a b', '/page%201#c d'], + anchors: ['你好', '#schr%C3%B6dingers-cat-principle'], + }, }, }); }); diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index 19fc413b1838..c1cbb88d726d 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -83,7 +83,9 @@ function getBrokenLinksForPage({ // it's a broken anchor if the target page exists // but the anchor does not exist on that page - return !targetPage.anchors.includes(hash); + return !targetPage.anchors.some((anchor) => + [hash, decodeURIComponent(hash)].includes(anchor), + ); } const brokenLinks = pageLinks.flatMap((link) => { From 64d1b42943497e8adde0c7bd52ed27de66219a08 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 23:41:02 +0100 Subject: [PATCH 19/24] Link component should collect id anchors --- packages/docusaurus/src/client/exports/Link.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/docusaurus/src/client/exports/Link.tsx b/packages/docusaurus/src/client/exports/Link.tsx index 427c24b79af0..3c02a025a81a 100644 --- a/packages/docusaurus/src/client/exports/Link.tsx +++ b/packages/docusaurus/src/client/exports/Link.tsx @@ -150,6 +150,10 @@ function Link( brokenLinks.collectLink(targetLink!); } + if (props.id) { + brokenLinks.collectAnchor(props.id); + } + return isRegularHtmlLink ? ( // eslint-disable-next-line jsx-a11y/anchor-has-content, @docusaurus/no-html-links Date: Thu, 11 Jan 2024 22:48:59 +0000 Subject: [PATCH 20/24] refactor: apply lint autofix --- project-words.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/project-words.txt b/project-words.txt index 2366a73e1db4..9f4393e4717c 100644 --- a/project-words.txt +++ b/project-words.txt @@ -66,6 +66,7 @@ datagit Datagit's dedup devto +dingers Dmitry docsearch Docsify @@ -401,3 +402,4 @@ yangshunz Zhou zoomable zpao +ödingers From 4fe43f656d2517f0d8c8ef801671512ed95d76b0 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Thu, 11 Jan 2024 23:50:29 +0100 Subject: [PATCH 21/24] micro optim --- packages/docusaurus/src/server/brokenLinks.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/docusaurus/src/server/brokenLinks.ts b/packages/docusaurus/src/server/brokenLinks.ts index c1cbb88d726d..b0b8ae77fd58 100644 --- a/packages/docusaurus/src/server/brokenLinks.ts +++ b/packages/docusaurus/src/server/brokenLinks.ts @@ -83,9 +83,8 @@ function getBrokenLinksForPage({ // it's a broken anchor if the target page exists // but the anchor does not exist on that page - return !targetPage.anchors.some((anchor) => - [hash, decodeURIComponent(hash)].includes(anchor), - ); + const hashes = [hash, decodeURIComponent(hash)]; + return !targetPage.anchors.some((anchor) => hashes.includes(anchor)); } const brokenLinks = pageLinks.flatMap((link) => { From 706f0e68a4a1f532173fe4324f127b615fab4f56 Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Fri, 12 Jan 2024 13:02:26 +0100 Subject: [PATCH 22/24] MDX footnotes LI should collect anchors --- .eslintrc.js | 5 ++++- .../src/theme-classic.d.ts | 8 ++++++++ .../src/theme/MDXComponents/Li.tsx | 18 ++++++++++++++++++ .../src/theme/MDXComponents/index.tsx | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx diff --git a/.eslintrc.js b/.eslintrc.js index 6a0b15228fd0..c6cea664f8dd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -203,7 +203,10 @@ module.exports = { })), ], 'no-template-curly-in-string': WARNING, - 'no-unused-expressions': [WARNING, {allowTaggedTemplates: true}], + 'no-unused-expressions': [ + WARNING, + {allowTaggedTemplates: true, allowShortCircuit: true}, + ], 'no-useless-escape': WARNING, 'no-void': [ERROR, {allowAsStatement: true}], 'prefer-destructuring': WARNING, diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index b894974807d8..a54f0799a81e 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -867,6 +867,14 @@ declare module '@theme/MDXComponents/Ul' { export default function MDXUl(props: Props): JSX.Element; } +declare module '@theme/MDXComponents/Li' { + import type {ComponentProps} from 'react'; + + export interface Props extends ComponentProps<'li'> {} + + export default function MDXLi(props: Props): JSX.Element; +} + declare module '@theme/MDXComponents/Img' { import type {ComponentProps} from 'react'; diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx new file mode 100644 index 000000000000..9d883e05072d --- /dev/null +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx @@ -0,0 +1,18 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React, {type ReactNode} from 'react'; +import useBrokenLinks from '@docusaurus/useBrokenLinks'; +import type {Props} from '@theme/MDXComponents/Li'; + +export default function MDXLi(props: Props): ReactNode | undefined { + // MDX Footnotes have ids such as
  • + const brokenLinks = useBrokenLinks(); + props.id && brokenLinks.collectAnchor(props.id); + + return
  • ; +} diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx index 5d7ce92f61f6..49d438bc5f68 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/index.tsx @@ -13,6 +13,7 @@ import MDXPre from '@theme/MDXComponents/Pre'; import MDXDetails from '@theme/MDXComponents/Details'; import MDXHeading from '@theme/MDXComponents/Heading'; import MDXUl from '@theme/MDXComponents/Ul'; +import MDXLi from '@theme/MDXComponents/Li'; import MDXImg from '@theme/MDXComponents/Img'; import Admonition from '@theme/Admonition'; import Mermaid from '@theme/Mermaid'; @@ -27,6 +28,7 @@ const MDXComponents: MDXComponentsObject = { a: MDXA, pre: MDXPre, ul: MDXUl, + li: MDXLi, img: MDXImg, h1: (props: ComponentProps<'h1'>) => , h2: (props: ComponentProps<'h2'>) => , From 8e66e05d250f98f3d7de8549ba36e087d5a5046f Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Fri, 12 Jan 2024 14:54:05 +0100 Subject: [PATCH 23/24] Allow to collect undefined links/anchors --- packages/docusaurus-module-type-aliases/src/index.d.ts | 4 ++-- .../src/theme/MDXComponents/Li.tsx | 3 +-- .../src/components/Details/index.tsx | 3 +++ packages/docusaurus/src/client/BrokenLinksContext.tsx | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 5cb44f06e402..0819c6efeaad 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -262,8 +262,8 @@ declare module '@docusaurus/useRouteContext' { declare module '@docusaurus/useBrokenLinks' { export type BrokenLinks = { - collectLink: (link: string) => void; - collectAnchor: (anchor: string) => void; + collectLink: (link: string | undefined) => void; + collectAnchor: (anchor: string | undefined) => void; }; export default function useBrokenLinks(): BrokenLinks; diff --git a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx index 9d883e05072d..74a8a4add4f1 100644 --- a/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx +++ b/packages/docusaurus-theme-classic/src/theme/MDXComponents/Li.tsx @@ -11,8 +11,7 @@ import type {Props} from '@theme/MDXComponents/Li'; export default function MDXLi(props: Props): ReactNode | undefined { // MDX Footnotes have ids such as
  • - const brokenLinks = useBrokenLinks(); - props.id && brokenLinks.collectAnchor(props.id); + useBrokenLinks().collectAnchor(props.id); return
  • ; } diff --git a/packages/docusaurus-theme-common/src/components/Details/index.tsx b/packages/docusaurus-theme-common/src/components/Details/index.tsx index 0876cf9b94d3..1046cae05c41 100644 --- a/packages/docusaurus-theme-common/src/components/Details/index.tsx +++ b/packages/docusaurus-theme-common/src/components/Details/index.tsx @@ -12,6 +12,7 @@ import React, { type ReactElement, } from 'react'; import clsx from 'clsx'; +import useBrokenLinks from '@docusaurus/useBrokenLinks'; import useIsBrowser from '@docusaurus/useIsBrowser'; import {useCollapsible, Collapsible} from '../Collapsible'; import styles from './styles.module.css'; @@ -47,6 +48,8 @@ export function Details({ children, ...props }: DetailsProps): JSX.Element { + useBrokenLinks().collectAnchor(props.id); + const isBrowser = useIsBrowser(); const detailsRef = useRef(null); diff --git a/packages/docusaurus/src/client/BrokenLinksContext.tsx b/packages/docusaurus/src/client/BrokenLinksContext.tsx index e04e8ab14731..8c8512ef81e8 100644 --- a/packages/docusaurus/src/client/BrokenLinksContext.tsx +++ b/packages/docusaurus/src/client/BrokenLinksContext.tsx @@ -18,11 +18,11 @@ export const createStatefulBrokenLinks = (): StatefulBrokenLinks => { const allAnchors = new Set(); const allLinks = new Set(); return { - collectAnchor: (anchor: string): void => { - allAnchors.add(anchor); + collectAnchor: (anchor: string | undefined): void => { + typeof anchor !== 'undefined' && allAnchors.add(anchor); }, - collectLink: (link: string): void => { - allLinks.add(link); + collectLink: (link: string | undefined): void => { + typeof link !== 'undefined' && allLinks.add(link); }, getCollectedAnchors: (): string[] => [...allAnchors], getCollectedLinks: (): string[] => [...allLinks], From 890e8b66cbbdf76d10adb8c698f67584ee4888ba Mon Sep 17 00:00:00 2001 From: sebastienlorber Date: Fri, 12 Jan 2024 14:55:58 +0100 Subject: [PATCH 24/24] fix useBrokenLinks docs examples --- website/docs/docusaurus-core.mdx | 18 ++++++------------ .../version-3.1.0/docusaurus-core.mdx | 16 ++++++++-------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/website/docs/docusaurus-core.mdx b/website/docs/docusaurus-core.mdx index cdb5a6fcf4a1..8c598e0bd8bd 100644 --- a/website/docs/docusaurus-core.mdx +++ b/website/docs/docusaurus-core.mdx @@ -627,24 +627,18 @@ Usage example: ```js title="MyHeading.js" import useBrokenLinks from '@docusaurus/useBrokenLinks'; -export default function MyHeading({id, ...props}): JSX.Element { - const brokenLinks = useBrokenLinks(); - - brokenLinks.collectAnchor(id); - - return

    Heading

    ; +export default function MyHeading(props) { + useBrokenLinks().collectAnchor(props.id); + return

    ; } ``` ```js title="MyLink.js" import useBrokenLinks from '@docusaurus/useBrokenLinks'; -export default function MyLink({targetLink, ...props}): JSX.Element { - const brokenLinks = useBrokenLinks(); - - brokenLinks.collectLink(targetLink); - - return Link; +export default function MyLink(props) { + useBrokenLinks().collectLink(props.href); + return ; } ``` diff --git a/website/versioned_docs/version-3.1.0/docusaurus-core.mdx b/website/versioned_docs/version-3.1.0/docusaurus-core.mdx index f22677d28e6f..6222bb3bd1f9 100644 --- a/website/versioned_docs/version-3.1.0/docusaurus-core.mdx +++ b/website/versioned_docs/version-3.1.0/docusaurus-core.mdx @@ -622,19 +622,19 @@ Usage example: ```js title="MyHeading.js" import useBrokenLinks from '@docusaurus/useBrokenLinks'; -export default function MyHeading({id, ...props}): JSX.Element { - const brokenLinks = useBrokenLinks(); - brokenLinks.collectAnchor(id); - return

    Heading

    ; + +export default function MyHeading(props) { + useBrokenLinks().collectAnchor(props.id); + return

    ; } ``` ```js title="MyLink.js" import useBrokenLinks from '@docusaurus/useBrokenLinks'; -export default function MyLink({targetLink, ...props}): JSX.Element { - const brokenLinks = useBrokenLinks(); - brokenLinks.collectLink(targetLink); - return Link; + +export default function MyLink(props) { + useBrokenLinks().collectLink(props.href); + return ; } ```