Add anchor links to headings
Some checks failed
Build And Publish / BuildAndPublish (push) Failing after 1m50s

This commit is contained in:
r-freeman 2024-09-18 17:36:21 +01:00
parent 0d29696705
commit 1715e0c275
2 changed files with 6 additions and 2 deletions

View File

@ -1,3 +1,5 @@
export function createSlug(title: string) {
return title.toLowerCase().replace(/[.,\s]+/g, '-')
return title.toLowerCase()
.replace(/\?/g, '')
.replace(/[.,\s]+/g, '-')
}

View File

@ -1,4 +1,5 @@
import type { MDXComponents } from 'mdx/types'
import type {MDXComponents} from 'mdx/types'
import {createSlug} from './lib/createSlug'
// This file allows you to provide custom React components
// to be used in MDX files. You can import and use any
@ -8,6 +9,7 @@ import type { MDXComponents } from 'mdx/types'
// This file is required to use MDX in `app` directory.
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
h2: ({children}) => <h2>{children}<a className='ml-1' href={`#${createSlug(children)}`}>#</a></h2>,
// Allows customizing built-in components, e.g. to add styling.
// h1: ({ children }) => <h1 style={{ fontSize: "100px" }}>{children}</h1>,
...components,