Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sharp-boats-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/gatsby-theme-doctocat": minor
---

You can now make custom React components globally available (no import required) to all markdown files in your site.
3 changes: 1 addition & 2 deletions docs/content/components/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
title: Components
---


Doctocat exports a collection of components that can be imported in your project and used to enhance your markdown files.
Doctocat provides a collection of React components that are globally available in all `.md` and `.mdx` files (no import required).
28 changes: 25 additions & 3 deletions docs/content/usage/customization.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
title: Customization
description: Here are a few ways you can customize your Doctocat site.
---

import {BorderBox} from '@primer/components'
import {Contributors} from '@primer/gatsby-theme-doctocat'

Here are a few ways you can customize your Doctocat site:

## Site metadata

You can customize your site's metadata via the `siteMetadata` object in `gatsby-config.js`:
Expand Down Expand Up @@ -40,7 +39,7 @@ Side navigation for your site is generated from the content in `src/@primer/gats
url: /example/example-2
```

_Note: Doctocat only supports one level of nesting._
<Note variant="warning">Doctocat only supports one level of nesting.</Note>

## Repository

Expand Down Expand Up @@ -177,3 +176,26 @@ Doctocat uses [`gatsby-plugin-manifest`](https://www.gatsbyjs.org/packages/gatsb
- 512x512 pixels or larger.
- Square. If it’s not, the image will be [letterboxed](<https://en.wikipedia.org/wiki/Letterboxing_(filming)>) with a transparent background.
- JPEG, PNG, WebP, TIFF, GIF, or SVG format.

## MDX components

Doctocat uses [MDX](https://mdxjs.com/) to allow you to embed React components in your markdown files and provides a few React [components](/components) that are globally available in all `.md` and `.mdx` files (no import required). To add custom components to this list of globally available components, create an `mdx-components.js` file in `src/@primer/gatsby-theme-doctocat/` and export your custom components from this file:

```js
// src/@primer/gatsby-theme-doctocat/mdx-components.js
import {SomeComponent} from 'path/to/some-component'

export default {
SomeComponent,
}
```

```md
---
title: Some markdown file
---

You can now use your component in any markdown file like so:

<SomeComponent />
```
6 changes: 4 additions & 2 deletions theme/src/components/wrap-root-element.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {MDXProvider} from '@mdx-js/react'
import {Link, ThemeProvider} from '@primer/components'
import React from 'react'
import mdxComponents from '../mdx-components'
import Blockquote from './blockquote'
import Caption from './caption'
import Code from './code'
Expand Down Expand Up @@ -36,13 +37,14 @@ const components = {
ol: List.withComponent('ol'),
dl: DescriptionList,

// Shortcodes (https://mdxjs.com/blog/shortcodes)
// Custom components
Note,
Do,
Dont,
DoDontContainer,
Caption,
ImageContainer
ImageContainer,
...mdxComponents
}

function wrapRootElement({element}) {
Expand Down
2 changes: 2 additions & 0 deletions theme/src/mdx-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Users can shadow this file to add custom components to scope of all MDX files.
export default {}