Skip to content

Commit

Permalink
feat: add gatsbyRemarkPlugins option (#146)
Browse files Browse the repository at this point in the history
Co-authored-by: Jo茫o Pedro Schmitz <oi@joaopedro.cc>
  • Loading branch information
aaronamm and jpedroschmitz committed Nov 17, 2022
1 parent 3768677 commit a4903ae
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changeset/pink-feet-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocketseat/gatsby-theme-docs': minor
'@rocketseat/gatsby-theme-docs-core': minor
---

Add `gatsbyRemarkPlugins` option
11 changes: 9 additions & 2 deletions @rocketseat/gatsby-theme-docs-core/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ const camelCase = require('lodash.camelcase');
const upperFirst = (text) => text.charAt(0).toUpperCase() + text.slice(1);

module.exports = (options) => {
const { basePath, configPath, docsPath, yamlFilesPath, withMdx } =
withDefault(options);
const {
basePath,
configPath,
docsPath,
yamlFilesPath,
withMdx,
gatsbyRemarkPlugins,
} = withDefault(options);

return {
siteMetadata: {
Expand Down Expand Up @@ -77,6 +83,7 @@ module.exports = (options) => {
},
`gatsby-remark-responsive-iframe`,
`gatsby-remark-copy-linked-files`,
...gatsbyRemarkPlugins,
],
plugins: [`gatsby-remark-autolink-headers`, `gatsby-remark-images`],
},
Expand Down
3 changes: 3 additions & 0 deletions @rocketseat/gatsby-theme-docs-core/util/with-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = (themeOptions) => {
const baseDir = themeOptions.baseDir || ``;
const withMdx =
themeOptions.withMdx === undefined ? true : themeOptions.withMdx;
const gatsbyRemarkPlugins = themeOptions.gatsbyRemarkPlugins || [];

const { githubUrl, repositoryUrl = '' } = themeOptions;

return {
Expand All @@ -19,5 +21,6 @@ module.exports = (themeOptions) => {
repositoryUrl,
withMdx,
branch,
gatsbyRemarkPlugins,
};
};
8 changes: 4 additions & 4 deletions @rocketseat/gatsby-theme-docs/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const withDefault = require('@rocketseat/gatsby-theme-docs-core/util/with-default');

module.exports = (options) => {
const themeOtions = withDefault(options);
const themeOptions = withDefault(options);

return {
siteMetadata: {
Expand All @@ -13,13 +13,13 @@ module.exports = (options) => {
siteAuthor: `@jpedroschmitz`,
siteImage: `/banner.png`,
siteLanguage: `en`,
basePath: themeOtions.basePath,
docsPath: themeOtions.docsPath,
basePath: themeOptions.basePath,
docsPath: themeOptions.docsPath,
},
plugins: [
{
resolve: `@rocketseat/gatsby-theme-docs-core`,
options: themeOtions,
options: themeOptions,
},
`gatsby-plugin-catch-links`,
`gatsby-plugin-emotion`,
Expand Down
1 change: 1 addition & 0 deletions examples/gatsby-theme-docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
yamlFilesPath: `src/yamlFiles`,
repositoryUrl: `https://github.com/jpedroschmitz/rocketdocs`,
baseDir: `examples/gatsby-theme-docs`,
gatsbyRemarkPlugins: [],
},
},
{
Expand Down
2 changes: 2 additions & 0 deletions examples/gatsby-theme-docs/src/config/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
link: '/usage/shadowing'
- label: 'Using YAML files'
link: '/usage/using-yaml-files'
- label: 'Remark Plugins'
link: '/usage/remark-plugins'
- label: More
items:
- label: FAQ
Expand Down
66 changes: 66 additions & 0 deletions examples/gatsby-theme-docs/src/docs/usage/remark-plugins.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
title: Remark plugins
description: Learn how to use Remark plugins in Rocket Docs.
---

To use a Remark plugin, you need to set the plugin name on this theme's `gatsbyRemarkPlugins` option.

## Example usage

Given that we want to use [Graphviz](https://graphviz.org/) in our Markdown files, we need to install the Remark plugin and add it on to `gatsbyRemarkPlugins` option on `gatsby.config.js`.

```sh
# Using Yarn:
yarn add gatsby-remark-graphviz
# Using NPM:
npm i gatsby-remark-graphviz
```

```js title=gatsby-config.js
module.exports = {
siteMetadata: {
// ...
},
plugins: [
{
resolve: `@rocketseat/gatsby-theme-docs`,
options: {
// ...
gatsbyRemarkPlugins: [
{
`gatsby-remark-graphviz`,
}
]
},
}
]
}
```

## Using a custom Remark Transformer plugin

If you use a local plugin, you must point to its location in the project through `require.resolve`.

```js title=gatsby-config.js
module.exports = {
siteMetadata: {
// ...
},
plugins: [
{
resolve: `@rocketseat/gatsby-theme-docs`,
options: {
// ...
gatsbyRemarkPlugins: [
{
`gatsby-remark-graphviz`,
resolve: require.resolve(`./plugins/gatsby-remark-purple-headers`)
}
]
},
}
]
}
```

For more information on how to create a Remark Transformer plugin, please refer to the [Creating a Remark Transformer Plugin](https://www.gatsbyjs.com/tutorial/remark-plugin-tutorial/) document.

0 comments on commit a4903ae

Please sign in to comment.