Skip to content

Commit

Permalink
chore(netlify-cms): update for v2, add standalone build system
Browse files Browse the repository at this point in the history
  • Loading branch information
erquhart committed Jul 13, 2018
1 parent 9c34da2 commit 96f3be4
Show file tree
Hide file tree
Showing 7 changed files with 418 additions and 903 deletions.
104 changes: 81 additions & 23 deletions packages/gatsby-plugin-netlify-cms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ install and configure. For more details, check out the [docs
site](https://netlifycms.org).

## Install

```shell
npm install --save netlify-cms
npm install --save gatsby-plugin-netlify-cms
npm install --save netlify-cms gatsby-plugin-netlify-cms
```

## How to use

Add the Netlify CMS plugin in your `gatsby-config.js`:

```javascript
Expand All @@ -26,23 +23,28 @@ Then add your Netlify CMS [configuration
file](https://www.netlifycms.org/docs/add-to-your-site/#configuration) in
`static/admin/config.yml`.

## Configuration
## Options
Netlify CMS can be configured via the plugin options below. You can learn
about how to pass options to plugins in the [Gatsby
docs](https://www.gatsbyjs.org/docs/plugins/#how-to-use-gatsby-plugins).

### `modulePath` (__optional__, default: `undefined`)
If you need to customize Netlify CMS, e.g. registering [custom
widgets](https://www.netlifycms.org/docs/custom-widgets/#registerwidget) or
styling the [preview
pane](https://www.netlifycms.org/docs/customization/#registerpreviewstyle),
you'll need to do so in a js module and provide Gatsby with the path to your
module. In `gatsby-config.js`, instead of simply adding the name of the plugin
to the `plugins` array, you'll need to use an object:
you'll need to do so in a JavaScript module and provide Gatsby with the path to
your module via the `modulePath` option:

```javascript
plugins: [
{
resolve: `gatsby-plugin-netlify-cms`,
options: {
// One convention is to place your Netlify CMS customization code in a
// `src/cms` directory.
/**
* One convention is to place your Netlify CMS customization code in a
* `src/cms` directory.
*/
modulePath: `${__dirname}/src/cms/cms.js`,
},
},
Expand All @@ -52,21 +54,77 @@ plugins: [
The js module might look like this:

```javascript
// Your module must at least include these three imports
import React from "react"
import CMS from "netlify-cms"
import "netlify-cms/dist/cms.css"

// Let's say you've created widget and preview components for a custom image
// gallery widget in separate files
import ImageGalleryWidget from "./image-gallery-widget.js"
import ImageGalleryPreview from "./image-gallery-preview.js"

// Register the imported widget:
CMS.registerWidget("image-gallery", ImageGalleryWidget, ImageGalleryPreview)
import CMS from `netlify-cms`

/**
* Let's say you've created widget and preview components for a custom image
* gallery widget in separate files:
*/
import ImageGalleryWidget from `./image-gallery-widget.js`
import ImageGalleryPreview from `./image-gallery-preview.js`

/**
* Register the imported widget:
*/
CMS.registerWidget(`image-gallery`, ImageGalleryWidget, ImageGalleryPreview)
```

## Support
### `enableIdentityWidget` (__optional__, default: `true`)
`enableIdentityWidget` is `true` by default, allowing [Netlify
Identity](https://www.netlify.com/docs/identity/) to be used without
configuration, but you may need to disable it in some cases, such as when using
a Netlify CMS backend that conflicts. This is currently known to be the case
when using the GitLab backend, but only when using implicit OAuth.

```javascript
plugins: [
{
resolve: `gatsby-plugin-netlify-cms`,
options: {
enableIdentityWidget: true,
},
},
]
```

### `stylesPath` (__optional__, default: `undefined`)
Gatsby template components can be used as [preview
templates](https://www.netlifycms.org/docs/customization/) in Netlify CMS. To
apply your site styles to the preview pane as well, you would normally register
a [custom
stylesheet](https://www.netlifycms.org/docs/customization/#registerpreviewstyle),
but your Gatsby style source may be Sass or CSS modules, and can't be passed to
Netlify CMS as is. The `stylesPath` accepts a path or an array of paths to your
raw styles. The styles are built using the same Webpack and Babel configuration
that your Gatsby site uses, and the CSS output is automatically registered and
used in the preview pane.

### `publicPath` (__optional__, default: `"admin"`)
Customize the path to Netlify CMS on your Gatsby site.

### `htmlTitle` (__optional__, default: `Content Manager`)
Customize the value of the `title` tag in your CMS HTML (shows in the browser
bar).

## Example
Here is the plugin with example values for all options (note that no option is
required):

```javascript
plugins: [
{
resolve: `gatsby-plugin-netlify-cms`,
options: {
modulePath: `path/to/custom/script.js`, // default: undefined
stylesPath: `path/to/styles.sass`, // default: undefined
enableIdentityWidget: `true`,
publicPath: `admin`,
htmlTitle: `Content Manager`,
},
},
]
```

## Support
For help with integrating Netlify CMS with Gatsby, check out the community
[Gitter](https://gitter.im/netlify/netlifycms).
18 changes: 9 additions & 9 deletions packages/gatsby-plugin-netlify-cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
"url": "https://github.com/gatsbyjs/gatsby/issues"
},
"dependencies": {
"@babel/runtime": "7.0.0-beta.51",
"html-webpack-include-assets-plugin": "^1.0.4",
"friendly-errors-webpack-plugin": "^1.7.0",
"html-webpack-plugin": "^3.2.0",
"lodash": "^4.17.10",
"mini-css-extract-plugin": "^0.4.1",
"netlify-cms": "^1.3.5",
"netlify-identity-widget": "^1.4.11"
"netlify-identity-widget": "^1.4.11",
"webpack": "^4.16.0"
},
"devDependencies": {
"@babel/cli": "7.0.0-beta.51",
"@babel/core": "7.0.0-beta.51",
"cross-env": "^5.1.4"
"@babel/cli": "^7.0.0-beta.53",
"@babel/core": "^7.0.0-beta.53",
"cross-env": "^5.1.3"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-netlify-cms#readme",
"keywords": [
Expand All @@ -30,8 +30,8 @@
"license": "MIT",
"main": "index.js",
"peerDependencies": {
"gatsby": ">2.0.0-alpha",
"netlify-cms": "^1.0.0"
"gatsby": "^2.0.0-beta.29",
"netlify-cms": "^1.9.3"
},
"repository": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-netlify-cms",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby-plugin-netlify-cms/src/cms-identity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import netlifyIdentityWidget from "netlify-identity-widget"

window.netlifyIdentity = netlifyIdentityWidget
netlifyIdentityWidget.init()
8 changes: 3 additions & 5 deletions packages/gatsby-plugin-netlify-cms/src/cms.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* eslint-disable no-unused-vars */
/* eslint-env browser */
import CMS from "netlify-cms"
import "netlify-cms/dist/cms.css"
import netlifyIdentityWidget from "netlify-identity-widget"

window.netlifyIdentity = netlifyIdentityWidget
netlifyIdentityWidget.init()
if (NETLIFY_CMS_PREVIEW_STYLES_SET) {
CMS.registerPreviewStyle(`styles.css`)
}
20 changes: 11 additions & 9 deletions packages/gatsby-plugin-netlify-cms/src/gatsby-browser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import netlifyIdentityWidget from "netlify-identity-widget"

exports.onInitialClientRender = () => {
netlifyIdentityWidget.on(`init`, user => {
if (!user) {
netlifyIdentityWidget.on(`login`, () => {
document.location.href = `/admin/`
})
}
})
netlifyIdentityWidget.init()
exports.onInitialClientRender = (_, { enableIdentityWidget }) => {
if (enableIdentityWidget) {
netlifyIdentityWidget.on(`init`, user => {
if (!user) {
netlifyIdentityWidget.on(`login`, () => {
document.location.reload()
})
}
})
netlifyIdentityWidget.init()
}
}
Loading

0 comments on commit 96f3be4

Please sign in to comment.