diff --git a/website/astro.config.js b/website/astro.config.js
index a3e6ff2c8..1a5ff23ab 100644
--- a/website/astro.config.js
+++ b/website/astro.config.js
@@ -2,7 +2,10 @@ import { defineConfig } from 'astro/config'
import { unified } from '@astrojs/markdown-remark'
import starlight from '@astrojs/starlight'
import llmsTxt from 'starlight-llms-txt'
-import { rehypeTrailingSlash } from './rehype.js'
+import {
+ rehypeExternalLinks,
+ rehypeTrailingSlash
+} from './rehype.js'
const isProduction = process.env.NODE_ENV === 'production'
const chartTags = [
@@ -23,9 +26,30 @@ export default defineConfig({
trailingSlash: 'always',
markdown: {
processor: unified({
- rehypePlugins: [rehypeTrailingSlash]
+ // Docusaurus kept straight quotes and dots, and error messages are quoted as they are
+ smartypants: false,
+ rehypePlugins: [rehypeTrailingSlash, rehypeExternalLinks]
})
},
+ vite: {
+ plugins: [
+ {
+ name: 'sandbox-index',
+ // Unlike GitHub Pages, the dev server does not answer a directory of `public` with its index.html
+ configureServer(server) {
+ server.middlewares.use((req, _res, next) => {
+ const [path, query] = (req.url ?? '').split('?')
+
+ if (path.startsWith('/sandboxes/') && path.endsWith('/')) {
+ req.url = `${path}index.html${query === undefined ? '' : `?${query}`}`
+ }
+
+ next()
+ })
+ }
+ }
+ ]
+ },
// Pages of the Docusaurus website that have no counterpart
redirects: {
'/search': '/',
@@ -68,13 +92,19 @@ export default defineConfig({
label: 'GitHub',
icon: 'github',
href: 'https://github.com/reactchartjs/react-chartjs-2'
+ },
+ {
+ label: 'Questions in GitHub Discussions',
+ icon: 'comment-alt',
+ href: 'https://github.com/reactchartjs/react-chartjs-2/discussions/categories/q-a'
}
],
editLink: {
baseUrl: 'https://github.com/reactchartjs/react-chartjs-2/edit/master/website/'
},
components: {
- Sidebar: './src/components/Sidebar.astro'
+ PageSidebar: './src/components/PageSidebar.astro',
+ Footer: './src/components/Footer.astro'
},
plugins: [
llmsTxt({
diff --git a/website/rehype.js b/website/rehype.js
index 314bc2469..9fc6fabc8 100644
--- a/website/rehype.js
+++ b/website/rehype.js
@@ -1,3 +1,22 @@
+const SITE = 'https://react-chartjs-2.js.org'
+
+/**
+ * Calls the callback for every link of the tree, including the links inside JSX of MDX files.
+ * @param {import('hast').Parent} node - The node to walk.
+ * @param {(link: import('hast').Element) => void} callback - What to do with a link.
+ */
+function visitLinks(node, callback) {
+ for (const child of node.children ?? []) {
+ if (child.type === 'element' && child.tagName === 'a') {
+ callback(child)
+ }
+
+ if ('children' in child) {
+ visitLinks(child, callback)
+ }
+ }
+}
+
/**
* Appends the trailing slash to internal links of pages, so they lead straight to the page
* instead of a redirect: `/docs/migration-to-v4#tree-shaking` becomes `/docs/migration-to-v4/#tree-shaking`.
@@ -19,25 +38,27 @@ function addTrailingSlash(href) {
return `${pathname}/${rest}`
}
-/**
- * @param {import('hast').Parent} node - The node to walk.
- */
-function visitLinks(node) {
- for (const child of node.children ?? []) {
- if (child.type === 'element') {
- if (child.tagName === 'a') {
- const href = addTrailingSlash(child.properties?.href)
-
- if (href) {
- child.properties.href = href
- }
- }
+export function rehypeTrailingSlash() {
+ return tree => visitLinks(tree, (link) => {
+ const href = addTrailingSlash(link.properties?.href)
- visitLinks(child)
+ if (href) {
+ link.properties.href = href
}
- }
+ })
}
-export function rehypeTrailingSlash() {
- return visitLinks
+/**
+ * Opens links to other sites in a new tab, as the Docusaurus website did.
+ * @returns {(tree: import('hast').Root) => void} The transformer of the page.
+ */
+export function rehypeExternalLinks() {
+ return tree => visitLinks(tree, (link) => {
+ const { href } = link.properties ?? {}
+
+ if (typeof href === 'string' && /^https?:\/\//.test(href) && !href.startsWith(SITE)) {
+ link.properties.target = '_blank'
+ link.properties.rel = ['noopener', 'noreferrer']
+ }
+ })
}
diff --git a/website/src/components/Bwndw.astro b/website/src/components/Bwndw.astro
new file mode 100644
index 000000000..de9621f11
--- /dev/null
+++ b/website/src/components/Bwndw.astro
@@ -0,0 +1,47 @@
+---
+interface Props {
+ /** The id of the block, unique on the page. */
+ id: string
+ /** Whether the block is for wide screens, which show the right sidebar, or for the others. */
+ wide: boolean
+ class?: string
+}
+
+const { id, wide, class: className } = Astro.props
+---
+
+
+
+
+
diff --git a/website/src/components/Footer.astro b/website/src/components/Footer.astro
new file mode 100644
index 000000000..600c3657b
--- /dev/null
+++ b/website/src/components/Footer.astro
@@ -0,0 +1,16 @@
+---
+import Default from '@astrojs/starlight/components/Footer.astro'
+import Bwndw from './Bwndw.astro'
+
+// The pages with the right sidebar, where the other block is
+const { toc } = Astro.locals.starlightRoute
+---
+
+{toc && (
+ <>
+
+ {/* After both blocks, so the one that does not fit the screen is gone when it runs */}
+
+ >
+)}
+
diff --git a/website/src/components/PageSidebar.astro b/website/src/components/PageSidebar.astro
new file mode 100644
index 000000000..6d24dbe68
--- /dev/null
+++ b/website/src/components/PageSidebar.astro
@@ -0,0 +1,11 @@
+---
+import Default from '@astrojs/starlight/components/PageSidebar.astro'
+import Bwndw from './Bwndw.astro'
+
+const [title, ...headings] = Astro.locals.starlightRoute.toc?.items ?? []
+// A table of contents with the page title alone has nothing to navigate
+const hasContents = !(title?.children.length === 0 && headings.length === 0)
+---
+
+{hasContents ? : }
+
diff --git a/website/src/components/PropsTable.astro b/website/src/components/PropsTable.astro
index 1c61db203..614553bd9 100644
--- a/website/src/components/PropsTable.astro
+++ b/website/src/components/PropsTable.astro
@@ -46,6 +46,7 @@ if (!doc) {
function formatType(type: string) {
return type
.replace(/ \| undefined$/, '')
+ .replace(/ChartJSOrUndefined<([^>]+)>/, 'Chart<$1>')
.replace(/^_DeepPartialObject]+)>[\s\S]*$/, 'ChartOptions<$1>')
}
@@ -78,7 +79,7 @@ const props = Object.values(doc.props).map(({
{prop.see && (
<>
{' '}
- See more
+ See more
>
)}
diff --git a/website/src/components/Sidebar.astro b/website/src/components/Sidebar.astro
deleted file mode 100644
index 7eac416e3..000000000
--- a/website/src/components/Sidebar.astro
+++ /dev/null
@@ -1,27 +0,0 @@
----
-import Default from '@astrojs/starlight/components/Sidebar.astro'
----
-
-
-
-
-
-
diff --git a/website/src/content/docs/components/bubble.mdx b/website/src/content/docs/components/bubble.mdx
index 7f57c0b85..e4685764c 100644
--- a/website/src/content/docs/components/bubble.mdx
+++ b/website/src/content/docs/components/bubble.mdx
@@ -1,6 +1,7 @@
---
title: "Bubble"
description: "Description of Bubble component from react-chartjs-2."
+next: false
---
import PropsTable from '../../../components/PropsTable.astro'
diff --git a/website/src/content/docs/components/chart.mdx b/website/src/content/docs/components/chart.mdx
index ca17b8245..aaef14878 100644
--- a/website/src/content/docs/components/chart.mdx
+++ b/website/src/content/docs/components/chart.mdx
@@ -1,6 +1,7 @@
---
title: "Chart"
description: "Description of Chart component from react-chartjs-2."
+prev: Components
---
import PropsTable from '../../../components/PropsTable.astro'
diff --git a/website/src/content/docs/components/index.md b/website/src/content/docs/components/index.md
index 21bc9b32b..9d57111a9 100644
--- a/website/src/content/docs/components/index.md
+++ b/website/src/content/docs/components/index.md
@@ -1,6 +1,7 @@
---
title: "Components"
description: "List of react-chartjs-2 components."
+prev: false
---
Every component renders a `