@primer/doctocat-nextjs 0.0.2-rc.1da8f9a → 0.0.2-rc.5b7f8ce
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -6,4 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
- [#4](https://github.com/primer/doctocat-nextjs/pull/4) [`4f28982`](https://github.com/primer/doctocat-nextjs/commit/4f28982e327e75f199f28fad987f1e827deafeb2) Thanks [@joseph-lozano](https://github.com/joseph-lozano)! - Wrap links with Next's Link component
|
|
8
8
|
|
|
9
|
+
- [#6](https://github.com/primer/doctocat-nextjs/pull/6) [`afd4e17`](https://github.com/primer/doctocat-nextjs/commit/afd4e1762f6294a14942d415c693319a874cd3fb) Thanks [@rezrah](https://github.com/rezrah)! - - Add MDX to HTML overrides mechanism and apply to headings and anchors
|
|
10
|
+
|
|
11
|
+
- Added anchor links to headings to match current functionality on primer.style
|
|
12
|
+
|
|
9
13
|
- [#2](https://github.com/primer/doctocat-nextjs/pull/2) [`2742b32`](https://github.com/primer/doctocat-nextjs/commit/2742b3214e7a53416d23f0459dc389f7c22cf5a1) Thanks [@rezrah](https://github.com/rezrah)! - Remove code blocks stylesheet, now merged into global.css
|
|
@@ -2,9 +2,11 @@ import React, {useMemo} from 'react'
|
|
|
2
2
|
import NextLink from 'next/link'
|
|
3
3
|
import Head from 'next/head'
|
|
4
4
|
import type {Folder, MdxFile, NextraThemeLayoutProps} from 'nextra'
|
|
5
|
+
import {MDXProvider} from 'nextra/mdx'
|
|
5
6
|
import {useFSRoute} from 'nextra/hooks'
|
|
6
7
|
import {PencilIcon} from '@primer/octicons-react'
|
|
7
8
|
import {BaseStyles, Box as PRCBox, Breadcrumbs, PageLayout, ThemeProvider} from '@primer/react'
|
|
9
|
+
|
|
8
10
|
import {
|
|
9
11
|
Animate,
|
|
10
12
|
AnimationProvider,
|
|
@@ -32,6 +34,7 @@ import {TableOfContents} from '../table-of-contents/TableOfContents'
|
|
|
32
34
|
import bodyStyles from '../../../css/prose.module.css'
|
|
33
35
|
import {IndexCards} from '../index-cards/IndexCards'
|
|
34
36
|
import {useColorMode} from '../../context/color-modes/useColorMode'
|
|
37
|
+
import {getComponents} from '../../mdx-components/mdx-components'
|
|
35
38
|
|
|
36
39
|
const {publicRuntimeConfig} = getConfig()
|
|
37
40
|
|
|
@@ -162,7 +165,11 @@ export function Theme({children, pageOpts}: NextraThemeLayoutProps) {
|
|
|
162
165
|
</>
|
|
163
166
|
)}
|
|
164
167
|
<article className={route !== '/' && !isIndexPage ? bodyStyles.Prose : ''}>
|
|
165
|
-
{isIndexPage ?
|
|
168
|
+
{isIndexPage ? (
|
|
169
|
+
<IndexCards folderData={flatDocsDirectories} route={route} />
|
|
170
|
+
) : (
|
|
171
|
+
<MDXProvider components={getComponents()}>{children}</MDXProvider>
|
|
172
|
+
)}
|
|
166
173
|
</article>
|
|
167
174
|
<footer>
|
|
168
175
|
<Box marginBlockStart={64}>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
.Heading__anchor {
|
|
2
|
+
color: var(--brand-color-text-default) !important;
|
|
3
|
+
text-decoration: none !important;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.Heading__anchorIcon {
|
|
7
|
+
visibility: hidden;
|
|
8
|
+
margin-left: var(--base-size-8);
|
|
9
|
+
vertical-align: middle !important;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.Heading__anchor:hover .Heading__anchorIcon {
|
|
13
|
+
visibility: visible;
|
|
14
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import type {ComponentProps, ReactElement} from 'react'
|
|
3
|
+
import clsx from 'clsx'
|
|
4
|
+
import type {Components} from 'nextra/mdx'
|
|
5
|
+
|
|
6
|
+
import {LinkIcon} from '@primer/octicons-react'
|
|
7
|
+
import NextLink from 'next/link'
|
|
8
|
+
|
|
9
|
+
import styles from './mdx-components.module.css'
|
|
10
|
+
|
|
11
|
+
// Anchor links for Headings
|
|
12
|
+
function HeadingLink({
|
|
13
|
+
tag: Tag,
|
|
14
|
+
context,
|
|
15
|
+
children,
|
|
16
|
+
id,
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}: ComponentProps<'h2'> & {
|
|
20
|
+
tag: `h${2 | 3 | 4 | 5 | 6}`
|
|
21
|
+
context: {index: number}
|
|
22
|
+
}): ReactElement {
|
|
23
|
+
return (
|
|
24
|
+
<Tag {...props} id={id} className={clsx(className)}>
|
|
25
|
+
<NextLink href={`#${id}`} className={styles.Heading__anchor}>
|
|
26
|
+
{children} <LinkIcon className={styles.Heading__anchorIcon} size={16} />
|
|
27
|
+
</NextLink>
|
|
28
|
+
</Tag>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const Link = ({href = '', className, ...props}) => <NextLink href={href} {...props} />
|
|
33
|
+
export const getComponents = (): Components => {
|
|
34
|
+
const context = {index: 0}
|
|
35
|
+
return {
|
|
36
|
+
h2: props => <HeadingLink tag="h2" context={context} {...props} />,
|
|
37
|
+
h3: props => <HeadingLink tag="h3" context={context} {...props} />,
|
|
38
|
+
h4: props => <HeadingLink tag="h4" context={context} {...props} />,
|
|
39
|
+
h5: props => <HeadingLink tag="h5" context={context} {...props} />,
|
|
40
|
+
h6: props => <HeadingLink tag="h6" context={context} {...props} />,
|
|
41
|
+
a: Link,
|
|
42
|
+
}
|
|
43
|
+
}
|