Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit 936a52e

Browse files
committed
Initial commit
0 parents  commit 936a52e

File tree

11 files changed

+735
-0
lines changed

11 files changed

+735
-0
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["babel-preset-gatsby-package", { "browser": true }]]
3+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*.js

.npmignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Logs
2+
logs
3+
*.log
4+
5+
# Runtime data
6+
pids
7+
*.pid
8+
*.seed
9+
10+
# Directory for instrumented libs generated by jscoverage/JSCover
11+
lib-cov
12+
13+
# Coverage directory used by tools like istanbul
14+
coverage
15+
16+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17+
.grunt
18+
19+
# node-waf configuration
20+
.lock-wscript
21+
22+
# Compiled binary addons (http://nodejs.org/api/addons.html)
23+
build/Release
24+
25+
# Dependency directory
26+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
27+
node_modules
28+
*.un~
29+
yarn.lock
30+
src
31+
flow-typed
32+
coverage
33+
decls
34+
examples

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Changelog: `gatsby-plugin-static-cms`

README.md

Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
# gatsby-plugin-static-cms
2+
3+
## Overview
4+
5+
Automatically generates an `admin/index.html` with a default Static CMS implementation.
6+
7+
Static CMS is a React single page app for editing git based content via API.
8+
Its built for non-technical and technical editors alike, and its super easy to
9+
install and configure. For more details, check out the [docs
10+
site](https://staticjscms.netlify.app).
11+
12+
## Install
13+
14+
```shell
15+
npm install @staticcms/core gatsby-plugin-static-cms
16+
```
17+
18+
## How to use
19+
20+
Add the Static CMS plugin in your `gatsby-config.js`:
21+
22+
```javascript
23+
plugins: [`gatsby-plugin-static-cms`]
24+
```
25+
26+
Then add your Static CMS [configuration
27+
file](https://staticjscms.netlify.app/docs/add-to-your-site-cdn#configuration) in
28+
`static/admin/config.yml`.
29+
30+
## Options
31+
32+
Static CMS can be configured via the plugin options below. You can learn
33+
about how to pass options to plugins in the [Gatsby
34+
docs](https://www.gatsbyjs.com/docs/plugins/#how-to-use-gatsby-plugins).
35+
36+
### `modulePath`
37+
38+
(_optional_, type: `string | Array<string>`, default: `undefined`)
39+
40+
If you need to customize Static CMS, e.g. registering [custom
41+
widgets](https://staticjscms.netlify.app/docs/custom-widgets/#registerwidget) or
42+
styling the [preview
43+
pane](https://staticjscms.netlify.app/docs/customization/#registerpreviewstyle),
44+
you'll need to do so in a JavaScript module and provide Gatsby with the path to
45+
your module via the `modulePath` option. Any styles imported by this module (or
46+
by the modules that it imports, all the way down the chain) are automatically
47+
applied to the editor preview pane by the plugin.
48+
49+
```javascript
50+
plugins: [
51+
{
52+
resolve: `gatsby-plugin-static-cms`,
53+
options: {
54+
/**
55+
* One convention is to place your Static CMS customization code in a
56+
* `src/cms` directory.
57+
*/
58+
modulePath: `${__dirname}/src/cms/cms.js`,
59+
},
60+
},
61+
]
62+
```
63+
64+
The js module might look like this:
65+
66+
```javascript
67+
/**
68+
* The default export of `@staticcms/core` is an object with all of the Static CMS
69+
* extension registration methods, such as `registerWidget` and
70+
* `registerPreviewTemplate`.
71+
*/
72+
import CMS from "@staticcms/core"
73+
74+
/**
75+
* Any imported styles should be automatically be applied to the editor preview
76+
* pane thus eliminating the need to use `registerPreviewStyle` for imported
77+
* styles. However if you are experiencing build errors regarding importing css,
78+
* sass or scss into a cms module when deploying to the netlify platform, you
79+
* may need to follow the implementation found in netlify documentation here:
80+
* https://staticjscms.netlify.app/docs/beta-features/#raw-css-in-registerpreviewstyle
81+
* All of the example imports below would result in styles being applied to the
82+
* preview pane.
83+
*/
84+
import "module-that-imports-styles.js"
85+
import "styles.scss"
86+
import "../other-styles.css"
87+
88+
/**
89+
* Let's say you've created widget and preview components for a custom image
90+
* gallery widget in separate files:
91+
*/
92+
import ImageGalleryWidget from "./image-gallery-widget.js"
93+
import ImageGalleryPreview from "./image-gallery-preview.js"
94+
95+
/**
96+
* Register the imported widget:
97+
*/
98+
CMS.registerWidget(`image-gallery`, ImageGalleryWidget, ImageGalleryPreview)
99+
```
100+
101+
### `manualInit`
102+
103+
(_optional_, type: `boolean`, default: `false`)
104+
105+
Set this to `true` If you need to [manually initialize](https://staticjscms.netlify.app/docs/beta-features/#manual-initialization) Static CMS. The plugin will take care of setting `window.CMS_MANUAL_INIT` to `true`:
106+
107+
```javascript
108+
plugins: [
109+
{
110+
resolve: `gatsby-plugin-static-cms`,
111+
options: {
112+
manualInit: true,
113+
},
114+
},
115+
]
116+
```
117+
118+
The js module might look like this:
119+
120+
```javascript
121+
import CMS from "@staticcms/core"
122+
123+
/**
124+
* Optionally pass in a config object. This object will be merged into `config.yml` if it exists
125+
*/
126+
127+
CMS.init({
128+
config: {
129+
backend: {
130+
name: "git-gateway",
131+
},
132+
},
133+
})
134+
```
135+
136+
### `enableIdentityWidget`
137+
138+
(_optional_, type: `boolean`, default: `true`)
139+
140+
`enableIdentityWidget` is `true` by default, allowing [Netlify
141+
Identity](https://www.netlify.com/docs/identity/) to be used without
142+
configuration. Disable it when not using Netlify Identity to reduce bundle size.
143+
144+
```javascript
145+
plugins: [
146+
{
147+
resolve: `gatsby-plugin-static-cms`,
148+
options: {
149+
enableIdentityWidget: true,
150+
},
151+
},
152+
]
153+
```
154+
155+
### `publicPath`
156+
157+
(_optional_, type: `string`, default: `"admin"`)
158+
159+
Customize the path to Static CMS on your Gatsby site.
160+
161+
### `htmlTitle`
162+
163+
(_optional_, type: `string`, default: `Content Manager`)
164+
165+
Customize the value of the `title` tag in your CMS HTML (shows in the browser
166+
bar).
167+
168+
### `htmlFavicon`
169+
170+
(_optional_, type: `string`, default: `""`)
171+
172+
Customize the value of the `favicon` tag in your CMS HTML (shows in the browser
173+
bar).
174+
175+
### `includeRobots`
176+
177+
(_optional_, type: `boolean`, default: `false`)
178+
179+
By default, the CMS page is not indexed by crawlers. Use this to add a `meta` tag to invite robots to index the CMS page.
180+
181+
### `customizeWebpackConfig`
182+
183+
(_optional_, type: `function`)
184+
185+
Function to customize webpack configuration.
186+
187+
Function parameters:
188+
189+
- config: webpack configuration for StaticCMS
190+
- destructured object from onCreateWebpackConfig { store, stage, pathPrefix, getConfig, rules, loaders, plugins} as seen in https://www.gatsbyjs.com/docs/node-apis/#onCreateWebpackConfig
191+
192+
```javascript
193+
plugins: [
194+
{
195+
resolve: `gatsby-plugin-static-cms`,
196+
options: {
197+
customizeWebpackConfig: (config, { plugins }) => {
198+
const Plugin = require("...")
199+
200+
config.plugins.push(
201+
plugins.define({
202+
"process.env.MY_VAR": JSON.stringify("my var value"),
203+
})
204+
)
205+
206+
config.plugins.push(new Plugin())
207+
},
208+
},
209+
},
210+
]
211+
```
212+
213+
## Example
214+
215+
Here is the plugin with example values for all options (note that no option is
216+
required):
217+
218+
```javascript
219+
plugins: [
220+
{
221+
resolve: `gatsby-plugin-static-cms`,
222+
options: {
223+
modulePath: `path/to/custom/script.js`, // default: undefined
224+
enableIdentityWidget: true,
225+
publicPath: `admin`,
226+
htmlTitle: `Content Manager`,
227+
htmlFavicon: `path/to/favicon`,
228+
includeRobots: false,
229+
},
230+
},
231+
]
232+
```
233+
234+
## Disable widget on site
235+
236+
If you're not using Netlify Identity within your site you have the option to completely disable the widget (and not the CMS). To do so, add the following to `gatsby-node.js`:
237+
238+
```javascript
239+
const webpack = require(`webpack`)
240+
241+
exports.onCreateWebpackConfig = ({ actions }) => {
242+
actions.setWebpackConfig({
243+
plugins: [
244+
new webpack.IgnorePlugin({
245+
resourceRegExp: /^netlify-identity-widget$/,
246+
}),
247+
],
248+
})
249+
}
250+
```
251+
252+
## Support
253+
254+
For help with integrating Static CMS with Gatsby, check out the community
255+
[Slack](https://staticjscms.netlify.app/chat).

package.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"name": "gatsby-plugin-static-cms",
3+
"description": "A Gatsby plugin which generates the Static CMS single page app",
4+
"version": "1.0.0",
5+
"author": "Shawn Erquhart <[email protected]>",
6+
"bugs": {
7+
"url": "https://github.com/gatsbyjs/gatsby/issues"
8+
},
9+
"dependencies": {
10+
"@babel/runtime": "^7.15.4",
11+
"@soda/friendly-errors-webpack-plugin": "1.8.1",
12+
"copy-webpack-plugin": "^7.0.0",
13+
"html-webpack-plugin": "^5.3.2",
14+
"html-webpack-skip-assets-plugin": "^1.0.3",
15+
"html-webpack-tags-plugin": "^3.0.2",
16+
"lodash": "^4.17.21",
17+
"mini-css-extract-plugin": "1.6.2",
18+
"netlify-identity-widget": "^1.9.2"
19+
},
20+
"devDependencies": {
21+
"@babel/cli": "^7.15.4",
22+
"@babel/core": "^7.15.5",
23+
"babel-preset-gatsby-package": "^3.0.0-next.1",
24+
"cross-env": "^7.0.3",
25+
"react": "^18.2.0",
26+
"react-dom": "^18.2.0"
27+
},
28+
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-static-cms#readme",
29+
"keywords": [
30+
"gatsby",
31+
"gatsby-plugin",
32+
"netlify",
33+
"static-cms",
34+
"cms"
35+
],
36+
"license": "MIT",
37+
"main": "index.js",
38+
"peerDependencies": {
39+
"gatsby": "^5.0.0-alpha-v5",
40+
"@staticcms/core": "next",
41+
"react": "^18.0.0 || ^0.0.0",
42+
"react-dom": "^18.0.0 || ^0.0.0",
43+
"webpack": "^5.0.0"
44+
},
45+
"repository": {
46+
"type": "git",
47+
"url": "https://github.com/gatsbyjs/gatsby.git",
48+
"directory": "packages/gatsby-plugin-static-cms"
49+
},
50+
"scripts": {
51+
"build": "babel src --out-dir . --ignore \"**/__tests__\"",
52+
"prepare": "cross-env NODE_ENV=production npm run build",
53+
"watch": "babel -w src --out-dir . --ignore \"**/__tests__\""
54+
},
55+
"engines": {
56+
"node": ">=18.0.0"
57+
}
58+
}

src/cms-identity.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* global CMS_PUBLIC_PATH */
2+
import netlifyIdentityWidget from "netlify-identity-widget"
3+
4+
window.netlifyIdentity = netlifyIdentityWidget
5+
6+
const addLoginListener = () =>
7+
netlifyIdentityWidget.on(`login`, () => {
8+
document.location.href = `${__PATH_PREFIX__}/${CMS_PUBLIC_PATH}/`
9+
})
10+
11+
netlifyIdentityWidget.on(`init`, user => {
12+
if (!user) {
13+
addLoginListener()
14+
} else {
15+
netlifyIdentityWidget.on(`logout`, () => {
16+
addLoginListener()
17+
})
18+
}
19+
})
20+
21+
// Boot on next tick to prevent clashes with css injected into StaticCMS
22+
// preview pane.
23+
setImmediate(() => {
24+
netlifyIdentityWidget.init()
25+
})

0 commit comments

Comments
 (0)