Skip to content

Commit 3187062

Browse files
Initial commit
0 parents  commit 3187062

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+17040
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Project dependencies
2+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
3+
node_modules
4+
.cache/
5+
# Build directory
6+
public/
7+
static/admin/*.bundle.*
8+
.DS_Store
9+
yarn-error.log

.nvmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v9.10.0

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 gatsbyjs
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Gatsby & Netlify CMS Example
2+
3+
An example website built using Gatsby V2 and Netlify CMS. The website is a fake JavaScript meetup site that lists upcoming meetups, information about the meetup group, as well as a list of past meetups.
4+
5+
The purpose of the repository is to provide an idea of how a Gatsby project is structured with Netlify CMS. You can easily deploy your own instance of this application by clicking the button below:
6+
7+
[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/robertcoopercode/gatsby-netlify-cms)
8+
9+
## Local Development
10+
11+
### Prerequisites
12+
13+
- Node (see [.nvmrc](./.nvmrc) for version)
14+
15+
### Run the project
16+
17+
```
18+
$ git clone [email protected]:robertcoopercode/gatsby-netlify-cms.git
19+
$ cd gatsby-netlify-cms
20+
$ yarn
21+
$ yarn develop
22+
```
23+
24+
To test the CMS locally, you'll to need run a production build of the site:
25+
26+
```
27+
$ yarn build
28+
$ yarn serve
29+
```
30+
31+
### Setting up the CMS
32+
33+
For details on how to configure the CMS, take a look at the [Netlify CMS Docs](https://www.netlifycms.org/docs/intro).
34+
35+
## Useful Ressources
36+
- ["Official" Gatsby and Netlify CMS starter](https://github.com/netlify-templates/gatsby-starter-netlify-cms)
37+
This starter includes a blog built with Gatsby and Netlify CMS. It was actually used as the starting off point for this repository.

gatsby-config.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
module.exports = {
2+
siteMetadata: {
3+
title: "Gatsby + Netlify CMS Starter",
4+
},
5+
plugins: [
6+
"gatsby-plugin-react-helmet",
7+
"gatsby-plugin-sass",
8+
{
9+
resolve: "gatsby-source-filesystem",
10+
options: {
11+
path: `${__dirname}/src/pages`,
12+
name: "pages",
13+
},
14+
},
15+
{
16+
resolve: "gatsby-source-filesystem",
17+
options: {
18+
path: `${__dirname}/src/img`,
19+
name: "images",
20+
},
21+
},
22+
"gatsby-plugin-sharp",
23+
"gatsby-transformer-sharp",
24+
{
25+
resolve: "gatsby-transformer-remark",
26+
options: {
27+
plugins: [],
28+
},
29+
},
30+
{
31+
resolve: "gatsby-plugin-netlify-cms",
32+
options: {
33+
modulePath: `${__dirname}/src/cms/cms.js`,
34+
},
35+
},
36+
{
37+
resolve: `gatsby-plugin-favicon`,
38+
options: {
39+
logo: "./src/img/favicon.png",
40+
},
41+
},
42+
"gatsby-plugin-netlify", // make sure to keep it last in the array
43+
],
44+
};

gatsby-node.js

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const _ = require("lodash");
2+
const path = require("path");
3+
const { createFilePath } = require("gatsby-source-filesystem");
4+
5+
exports.createPages = ({ actions, graphql }) => {
6+
const { createPage } = actions;
7+
8+
return graphql(`
9+
{
10+
allMarkdownRemark(limit: 1000) {
11+
edges {
12+
node {
13+
id
14+
fields {
15+
slug
16+
}
17+
frontmatter {
18+
path
19+
templateKey
20+
}
21+
}
22+
}
23+
}
24+
}
25+
`).then(result => {
26+
if (result.errors) {
27+
result.errors.forEach(e => console.error(e.toString()));
28+
return Promise.reject(result.errors);
29+
}
30+
31+
// Filter out the footer, navbar, and meetups so we don't create pages for those
32+
const postOrPage = result.data.allMarkdownRemark.edges.filter(edge => {
33+
if (edge.node.frontmatter.templateKey === "navbar") {
34+
return false;
35+
} else if (edge.node.frontmatter.templateKey === "footer") {
36+
return false;
37+
} else {
38+
return !Boolean(edge.node.fields.slug.match(/^\/meetups\/.*$/));
39+
}
40+
});
41+
42+
postOrPage.forEach(edge => {
43+
let component, pathName;
44+
if (edge.node.frontmatter.templateKey === "home-page") {
45+
pathName = "/";
46+
component = path.resolve(`src/pages/index.js`);
47+
} else {
48+
pathName = edge.node.frontmatter.path || edge.node.fields.slug;
49+
component = path.resolve(`src/templates/${String(edge.node.frontmatter.templateKey)}.js`);
50+
}
51+
const id = edge.node.id;
52+
createPage({
53+
path: pathName,
54+
component,
55+
// additional data can be passed via context
56+
context: {
57+
id,
58+
},
59+
});
60+
});
61+
});
62+
};
63+
64+
exports.onCreateNode = ({ node, actions, getNode }) => {
65+
const { createNodeField } = actions;
66+
67+
if (node.internal.type === `MarkdownRemark`) {
68+
const value = createFilePath({ node, getNode });
69+
createNodeField({
70+
name: `slug`,
71+
node,
72+
value,
73+
});
74+
}
75+
};

netlify.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build]
2+
publish = "public"
3+
command = "npm run build"
4+
[build.environment]
5+
YARN_VERSION = "1.3.2"
6+
YARN_FLAGS = "--no-ignore-optional"

package.json

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "gatsby-starter-netlify-cms",
3+
"description": "Example Gatsby, and Netlify CMS project",
4+
"version": "1.1.3",
5+
"author": "Robert Cooper",
6+
"dependencies": {
7+
"date-fns": "^1.29.0",
8+
"gatsby": "^2.0.0",
9+
"gatsby-plugin-favicon": "^3.1.4",
10+
"gatsby-plugin-netlify": "^2.0.0",
11+
"gatsby-plugin-netlify-cms": "^3.0.0",
12+
"gatsby-plugin-react-helmet": "^3.0.0",
13+
"gatsby-plugin-sass": "^2.0.1",
14+
"gatsby-plugin-sharp": "^2.0.5",
15+
"gatsby-remark-images": "^2.0.1",
16+
"gatsby-source-filesystem": "^2.0.1",
17+
"gatsby-transformer-remark": "^2.1.1",
18+
"gatsby-transformer-sharp": "^2.1.1",
19+
"lodash": "^4.17.5",
20+
"lodash-webpack-plugin": "^0.11.4",
21+
"netlify-cms": "^2.1.1",
22+
"node-sass": "^4.9.2",
23+
"parcel-bundler": "^1.9.4",
24+
"prop-types": "^15.6.0",
25+
"react": "^16.2.0",
26+
"react-dom": "^16.4.1",
27+
"react-google-maps": "^9.4.5",
28+
"react-helmet": "^5.2.0",
29+
"react-markdown": "^4.0.3",
30+
"uuid": "^3.2.1"
31+
},
32+
"keywords": [
33+
"gatsby"
34+
],
35+
"license": "MIT",
36+
"main": "n/a",
37+
"scripts": {
38+
"start": "npm run develop",
39+
"clean": "rimraf .cache public",
40+
"build": "npm run clean && gatsby build",
41+
"develop": "npm run clean && gatsby develop",
42+
"serve": "gatsby serve",
43+
"format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"{gatsby-*.js,src/**/*.js}\"",
44+
"test": "echo \"Error: no test specified\" && exit 1"
45+
},
46+
"devDependencies": {
47+
"prettier": "^1.7.4",
48+
"rimraf": "^2.6.2"
49+
}
50+
}

renovate.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": [
3+
"config:base"
4+
],
5+
"rangeStrategy": "replace",
6+
"lockFileMaintenance": {
7+
"enabled": true,
8+
"extends": "schedule:weekly"
9+
}
10+
}

src/cms/cms.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import CMS from "netlify-cms";
2+
3+
import AboutPagePreview from "./preview-templates/AboutPagePreview";
4+
import HomePagePreview from "./preview-templates/HomePagePreview";
5+
import MeetupPreview from "./preview-templates/MeetupPreview";
6+
import FooterPreview from "./preview-templates/FooterPreview";
7+
import NavbarPreview from "./preview-templates/NavbarPreview";
8+
import PastMeetupsPagePreview from "./preview-templates/PastMeetupsPagePreview";
9+
10+
CMS.registerPreviewTemplate("meetups", MeetupPreview);
11+
CMS.registerPreviewTemplate("footer", FooterPreview);
12+
CMS.registerPreviewTemplate("navbar", NavbarPreview);
13+
CMS.registerPreviewTemplate("about", AboutPagePreview);
14+
CMS.registerPreviewTemplate("home", HomePagePreview);
15+
CMS.registerPreviewTemplate("pastMeetups", PastMeetupsPagePreview);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import { AboutPageTemplate } from "../../templates/about-page";
4+
5+
const AboutPagePreview = ({ entry, widgetFor }) => (
6+
<AboutPageTemplate
7+
page={{
8+
frontmatter: entry.getIn(["data"]).toJS(),
9+
html: entry.getIn(["data", "body"]),
10+
bodyIsMarkdown: true,
11+
}}
12+
/>
13+
);
14+
15+
AboutPagePreview.propTypes = {
16+
entry: PropTypes.shape({
17+
getIn: PropTypes.func,
18+
}),
19+
widgetFor: PropTypes.func,
20+
};
21+
22+
export default AboutPagePreview;
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
4+
import { FooterTemplate } from "../../components/Footer";
5+
6+
const FooterPreview = ({ entry }) => {
7+
const data = entry.getIn(["data"]).toJS();
8+
return <FooterTemplate data={data} />;
9+
};
10+
11+
FooterPreview.propTypes = {
12+
entry: PropTypes.shape({
13+
getIn: PropTypes.func,
14+
}),
15+
};
16+
17+
export default FooterPreview;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
4+
import { HomePageTemplate } from "../../pages/index";
5+
6+
const HomePagePreview = ({ entry }) => {
7+
const home = entry.getIn(["data"]).toJS();
8+
return <HomePageTemplate home={home} />;
9+
};
10+
11+
HomePagePreview.propTypes = {
12+
entry: PropTypes.shape({
13+
getIn: PropTypes.func,
14+
}),
15+
};
16+
17+
export default HomePagePreview;
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import format from "date-fns/format";
4+
5+
import MeetupTemplate from "../../templates/meetup";
6+
7+
const MeetupPreview = ({ entry }) => {
8+
const meetup = entry.getIn(["data"]).toJS();
9+
const rawDate = meetup.date;
10+
const formattedDate = format(rawDate, "MMMM Do YYYY @ h:mm A");
11+
return <MeetupTemplate meetup={{ ...meetup, formattedDate, rawDate }} />;
12+
};
13+
14+
MeetupPreview.propTypes = {
15+
entry: PropTypes.shape({
16+
getIn: PropTypes.func,
17+
}),
18+
};
19+
20+
export default MeetupPreview;
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
4+
import { NavbarTemplate } from "../../components/Navbar";
5+
6+
const NavbarPreview = ({ entry }) => {
7+
const data = entry.getIn(["data"]).toJS();
8+
return <NavbarTemplate data={data} />;
9+
};
10+
11+
NavbarPreview.propTypes = {
12+
entry: PropTypes.shape({
13+
getIn: PropTypes.func,
14+
}),
15+
};
16+
17+
export default NavbarPreview;

0 commit comments

Comments
 (0)