Skip to content

Conversation

@0x80
Copy link
Contributor

@0x80 0x80 commented Dec 14, 2018

When trying to work with the Netlify CMS plugin, I ran into an issue with images like #8195. I found it odd that I had to manually transform the image paths to relative paths to make them compatible with the gatsby-transformer-sharp plugin.

I think it's safe to assume that anyone working with the Netlify CMS will want to process their images for resizing and such, otherwise you would be missing a big part of what makes Gatsby perform great.

In this PR I have pulled the code for transforming images and some other standard tasks like creating a slug into the plugin code.

I have added two config options for the plugin:

  • contentFolder: This would be the root folder where all of your Netlify content lives, which defaults to "content".
  • imageFields: A list of frontmatter fields that hold paths to images. These fields will be transformed to relative paths.

Now that I think of it, imageFields should maybe be renamed to assetFields or mediaFields since I assume that you'd want to same transformation if you use other types of assets in the CMS.

Of course the docs would need to be updated also, but first I'm curious to get some feedback and verify if this is all a good idea to begin with.

With these changes you can start using the CMS without writing additional client code in gatsby-node.js, which is I think how a plugin should work ideally.

@0x80 0x80 self-assigned this Dec 14, 2018
@0x80 0x80 requested a review from erquhart December 14, 2018 20:55
@0x80 0x80 changed the title [WIP] Add standard frontmatter transforms to netlify cms plugin [RFC] Add standard frontmatter transforms to netlify cms plugin Dec 22, 2018
@0x80
Copy link
Contributor Author

0x80 commented Jan 20, 2019

I am unsure how to proceed on this. If it is considered a good idea I can wrap things up and document the changes in the plugin readme.

But I would like to have some sort of "go" before I do that.

@erquhart ?

@erquhart
Copy link
Contributor

I know it's been a wait, but I'd much rather see Netlify CMS output relative paths than to provide SSG-specific workarounds - this plugin already does so much more than I wish it did!

I'm guessing you already found this, but in case you didn't, here's the storied history of relative images in Netlify CMS: decaporg/decap-cms#325

@0x80
Copy link
Contributor Author

0x80 commented Jan 29, 2019

@erquhart Thanks for the heads up. I wasn't aware of the history of relative images in Netlify. I will read up on it 👍

@KyleAMathews
Copy link
Contributor

Looks like this is going to be fixed in Netlify CMS so I'll close this here. Thanks!

@erquhart
Copy link
Contributor

Relative image path support is now in beta as of Netlify CMS 2.9.8-beta.2 - try it out:

npm update netlify-cms-app@beta

Then add media_folder_relative: true to your Netlify CMS config.

Docs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants