@primer/doctocat-nextjs 0.0.2-rc.8aac513 → 0.0.2-rc.ac6ab68

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,10 @@
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
+ - [`6f21970`](https://github.com/primer/doctocat-nextjs/commit/6f21970c74f7635be89fc4cd20376d7fe5ca35e7) Thanks [@rezrah](https://github.com/rezrah)! - Switch hero image order with description and reduce `h2` block start margin
10
+
11
+ - [#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
12
+
13
+ - Added anchor links to headings to match current functionality on primer.style
14
+
9
15
  - [#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
 
@@ -132,16 +135,16 @@ export function Theme({children, pageOpts}: NextraThemeLayoutProps) {
132
135
  {frontMatter.title}
133
136
  </Heading>
134
137
  )}
135
- {frontMatter.image && (
136
- <Box paddingBlockEnd={16}>
137
- <Hero.Image src={frontMatter.image} alt={frontMatter['image-alt']} />
138
- </Box>
139
- )}
140
138
  {frontMatter.description && (
141
139
  <Text as="p" variant="muted" size="300">
142
140
  {frontMatter.description}
143
141
  </Text>
144
142
  )}
143
+ {frontMatter.image && (
144
+ <Box paddingBlockStart={16}>
145
+ <Hero.Image src={frontMatter.image} alt={frontMatter['image-alt']} />
146
+ </Box>
147
+ )}
145
148
  {frontMatter['action-1-text'] && (
146
149
  <Box paddingBlockStart={16}>
147
150
  <ButtonGroup>
@@ -162,7 +165,11 @@ export function Theme({children, pageOpts}: NextraThemeLayoutProps) {
162
165
  </>
163
166
  )}
164
167
  <article className={route !== '/' && !isIndexPage ? bodyStyles.Prose : ''}>
165
- {isIndexPage ? <IndexCards folderData={flatDocsDirectories} route={route} /> : children}
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
+ }
@@ -129,15 +129,12 @@
129
129
  letter-spacing: var(--brand-heading-letterSpacing-300);
130
130
  }
131
131
 
132
- .Prose :is(h1, h2, h3) {
133
- --spacing: var(--base-size-64);
134
- }
135
-
136
132
  .Prose :is(h1) {
133
+ --spacing: var(--base-size-64);
137
134
  margin-block-end: var(--spacing);
138
135
  }
139
136
 
140
- .Prose :is(h1, h2, h3) + * {
137
+ .Prose :is(h2, h3) + * {
141
138
  --spacing: var(--base-size-40);
142
139
  }
143
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/doctocat-nextjs",
3
- "version": "0.0.2-rc.8aac513",
3
+ "version": "0.0.2-rc.ac6ab68",
4
4
  "description": "A Next.js theme for building Primer documentation sites",
5
5
  "main": "index.js",
6
6
  "scripts": {