Skip to content

Commit

Permalink
Updates README
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Mahon <[email protected]>
  • Loading branch information
danielmahon committed May 14, 2018
1 parent 3e043d8 commit 2248c6e
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@

Convert image src(s) in markdown to be relative to their node's parent directory. This will help [gatsby-remark-images](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-remark-images) match images outside the node folder. For example, use with NetlifyCMS.

NOTE: This was built for use with NetlifyCMS and should be considered a temporary solution until relative paths are supported. If it works for other use cases than great!

## Install

`npm install --save gatsby-remark-relative-images`

## How to use

```javascript
// In your gatsby-config.js
// gatsby-config.js
plugins: [
// Add static assets before markdown files
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/static/uploads`,
name: 'uploads',
},
},
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/src/pages`,
name: 'pages',
},
},
{
resolve: `gatsby-transformer-remark`,
options: {
Expand All @@ -26,11 +36,6 @@ plugins: [
// go before gatsby-remark-images
{
resolve: `gatsby-remark-relative-images`,
options: {
// Set the name option to the same
// name you set for gatsby-source-filesystem
name: 'uploads', // default
},
},
{
resolve: `gatsby-remark-images`,
Expand All @@ -47,8 +52,15 @@ plugins: [
];
```

## Options
### To convert frontmatter images

Use the exported function `fmImagesToRelative` in your `gatsby-node.js`. This takes every node returned by your gatsby-source plugins and converts any absolute paths in markdown frontmatter data into relative paths if a matching file is found.

| Name | Default | Description |
| ------ | --------- | --------------------------------------------------------------------------------------- |
| `name` | `uploads` | Set the `name` option to the same `options.name` you set for `gatsby-source-filesystem` |
```js
// gatsby-node.js
const { fmImagesToRelative } = require('gatsby-remark-relative-images');

exports.onCreateNode = ({ node }) => {
fmImagesToRelative(node);
};
```

0 comments on commit 2248c6e

Please sign in to comment.