diff --git a/CHANGELOG.md b/CHANGELOG.md index e42daa2e3715e..0f77e73861c46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -529,7 +529,7 @@ export const pageQuery = ` } } } -` +`; ``` You must now write: @@ -545,7 +545,7 @@ export const pageQuery = graphql` } } } -` +`; ``` ## [1.0.0-alpha10] - 2016-11-17 diff --git a/docs/blog/2017-02-21-1-0-progress-update-where-came-from-where-going/index.md b/docs/blog/2017-02-21-1-0-progress-update-where-came-from-where-going/index.md index 80f2c102c2fbf..014dc65b19cf3 100644 --- a/docs/blog/2017-02-21-1-0-progress-update-where-came-from-where-going/index.md +++ b/docs/blog/2017-02-21-1-0-progress-update-where-came-from-where-going/index.md @@ -165,8 +165,8 @@ navigate around, Gatsby loads the JavaScript needed for each route. This means that one page with heavy imports: ```javascript -import d3 from "d3" -import threejs from "react-threejs" +import d3 from "d3"; +import threejs from "react-threejs"; ``` ...won't affect the performance of the rest of the site. @@ -281,11 +281,11 @@ the blog posts. Included with the component is an exported `pageQuery`. ```javascript // A simple React component for rendering a blog page. -import React from "react" +import React from "react"; class BlogPostTemplate extends React.Component { render() { - ;
+

{this.props.data.markdown.frontmatter.title}

{this.props.data.markdown.frontmatter.date}
-
+
; } } -export default BlogPostTemplate +export default BlogPostTemplate; export const pageQuery = ` query BlogPost($slug: String!) { @@ -311,7 +311,7 @@ export const pageQuery = ` } } } -` +`; ``` All data parsing and processing is plugin-driven. So in time, any imaginable diff --git a/docs/blog/2017-07-19-creating-a-blog-with-gatsby/index.md b/docs/blog/2017-07-19-creating-a-blog-with-gatsby/index.md index 02c8c7372e25b..9d8fe685805c5 100644 --- a/docs/blog/2017-07-19-creating-a-blog-with-gatsby/index.md +++ b/docs/blog/2017-07-19-creating-a-blog-with-gatsby/index.md @@ -255,15 +255,15 @@ We'll want to create the file `src/templates/blog-post.js` (please create the `src/templates` folder if it does not yet exist!). ```javascript -import React from "react" -import Helmet from "react-helmet" +import React from "react"; +import Helmet from "react-helmet"; // import '../css/blog-post.css'; // make it pretty! export default function Template({ data, // this prop will be injected by the GraphQL query we'll write in a bit }) { - const { markdownRemark: post } = data // data.markdownRemark holds our post data + const { markdownRemark: post } = data; // data.markdownRemark holds our post data return (
@@ -275,7 +275,7 @@ export default function Template({ />
- ) + ); } ``` @@ -377,13 +377,13 @@ Gatsby, as detailed in its [Node API specification][node-spec]. However, we only care about one particular API in this instance, `createPages`. ```javascript -const path = require("path") +const path = require("path"); exports.createPages = ({ boundActionCreators, graphql }) => { - const { createPage } = boundActionCreators + const { createPage } = boundActionCreators; - const blogPostTemplate = path.resolve(`src/templates/blog-post.js`) -} + const blogPostTemplate = path.resolve(`src/templates/blog-post.js`); +}; ``` Nothing super complex yet! We're using the `createPages` API (which Gatsby will @@ -541,14 +541,14 @@ create `src/pages/tags.js`, the path `http://localhost:8000/tags/` will be available within the browser and the statically generated site. ```javascript -import React from "react" -import Link from "gatsby-link" -import Helmet from "react-helmet" +import React from "react"; +import Link from "gatsby-link"; +import Helmet from "react-helmet"; // import '../css/index.css'; // add some style if you want! export default function Index({ data }) { - const { edges: posts } = data.allMarkdownRemark + const { edges: posts } = data.allMarkdownRemark; return (
{posts @@ -562,10 +562,10 @@ export default function Index({ data }) {

{post.frontmatter.date}

{post.excerpt}

- ) + ); })} - ) + ); } export const pageQuery = graphql` @@ -584,7 +584,7 @@ export const pageQuery = graphql` } } } -` +`; ``` OK! So we've followed a similar approach to our blog post template, so this diff --git a/docs/blog/2017-10-01-migrating-my-blog-from-hexo-to-gatsby/index.md b/docs/blog/2017-10-01-migrating-my-blog-from-hexo-to-gatsby/index.md index b2963f4aec326..aa825ceeb27b1 100644 --- a/docs/blog/2017-10-01-migrating-my-blog-from-hexo-to-gatsby/index.md +++ b/docs/blog/2017-10-01-migrating-my-blog-from-hexo-to-gatsby/index.md @@ -293,16 +293,16 @@ specify a `pageQuery` that will pass data into the default export of that page. ```jsx // src/pages/index.js -import React from "react" +import React from "react"; export default class BlogIndex extends React.Component { render() { // Handle graphql errors if (this.props.errors && this.props.errors.length) { this.props.errors.forEach(({ message }) => { - console.error(`BlogIndex render errr: ${message}`) - }) - return

Errors found: Check the console for details

+ console.error(`BlogIndex render errr: ${message}`); + }); + return

Errors found: Check the console for details

; } return ( @@ -312,7 +312,7 @@ export default class BlogIndex extends React.Component { {node.frontmatter.title} ))} - ) + ); } } @@ -328,7 +328,7 @@ export const pageQuery = graphql` } } } -` +`; ``` This is a simplified example, but there are a few things going on that might not @@ -352,7 +352,7 @@ Now let's looks specifically at where we render a link for each blog post: { this.props.data.allMarkdownRemark.edges.map(({ node }, i) => ( {node.frontmatter.title} - )) + )); } ``` @@ -376,7 +376,7 @@ export const pageQuery = graphql` } } } -` +`; ``` This is how you get data from Gatsby into your react components. Make sure you @@ -441,7 +441,7 @@ export const pageQuery = graphql` } } } -` +`; ``` ```jsx @@ -450,7 +450,7 @@ export const pageQuery = graphql` {node.frontmatter.title} - )) + )); } ``` @@ -495,15 +495,15 @@ we add custom fields. Example: ```js // gatsby-node.js -const { GraphQLString } = require("graphql") +const { GraphQLString } = require("graphql"); const getURL = node => { /* See the source link below for implementation */ -} +}; exports.setFieldsOnGraphQLNodeType = ({ type }) => { if (type.name !== "MarkdownRemark") { - return {} + return {}; } return Promise.resolve({ @@ -511,8 +511,8 @@ exports.setFieldsOnGraphQLNodeType = ({ type }) => { type: GraphQLString, resolve: node => getURL(node), }, - }) -} + }); +}; ``` > Source code for @@ -564,16 +564,16 @@ case, `createPages`. In the same `gatsby-node.js` file as before: // .. other stuff from before... exports.createPages = ({ boundActionCreators }) => { - const { createPage } = boundActionCreators - const postTemplate = path.resolve("./src/templates/custom-page.js") + const { createPage } = boundActionCreators; + const postTemplate = path.resolve("./src/templates/custom-page.js"); // Create a custom page! createPage({ path: `/my-custom-page/`, component: postTemplate, context: {}, // Context will be passed in to the page query as graphql variables - }) -} + }); +}; ``` At the most basic level this method of page creation is quite simple: Grab the @@ -600,8 +600,8 @@ markdownFiles.forEach(post => { context: { id: post.id, }, - }) -}) + }); +}); ``` I've included the pseudo code to highlight the fact that nothing too magical is @@ -618,8 +618,8 @@ work. // NOTE: I'm using async/await to simplify the code since it's now natively supported // in Node 8.x. This means that our function will return a promise exports.createPages = async ({ graphql, boundActionCreators }) => { - const { createPage } = boundActionCreators - const postTemplate = path.resolve("./src/templates/post.js") + const { createPage } = boundActionCreators; + const postTemplate = path.resolve("./src/templates/post.js"); // Using async await. Query will likely be very similar to your pageQuery in index.js const result = await graphql(` @@ -633,11 +633,11 @@ exports.createPages = async ({ graphql, boundActionCreators }) => { } } } - `) + `); if (result.errors) { - console.log(result.errors) - throw new Error("Things broke, see console output above") + console.log(result.errors); + throw new Error("Things broke, see console output above"); } // Create blog posts pages. @@ -649,9 +649,9 @@ exports.createPages = async ({ graphql, boundActionCreators }) => { // Context will be passed in to the page query as graphql vars id: node.id, }, - }) - }) -} + }); + }); +}; ``` Notice that the query is very similar to the `pageQuery` in index.js but it's @@ -671,11 +671,11 @@ Here it is in all it's glory: ```jsx // src/templates/post.js -import React from "react" +import React from "react"; export default class BlogPost extends React.Component { render() { - const post = this.props.data.markdownRemark + const post = this.props.data.markdownRemark; return (
@@ -685,7 +685,7 @@ export default class BlogPost extends React.Component { className="content" />
- ) + ); } } @@ -699,7 +699,7 @@ export const pageQuery = graphql` html } } -` +`; ``` If you're not used to GraphQL syntax the `pageQuery` might be a little diff --git a/docs/blog/2017-10-05-portfolio-site-gatsby-wordpress/index.md b/docs/blog/2017-10-05-portfolio-site-gatsby-wordpress/index.md index 7f8c57545b4f4..ecdcf0370a7a7 100644 --- a/docs/blog/2017-10-05-portfolio-site-gatsby-wordpress/index.md +++ b/docs/blog/2017-10-05-portfolio-site-gatsby-wordpress/index.md @@ -81,7 +81,7 @@ export const projectsPageQuery = graphql` } } } -` +`; ``` Pulling blog posts was even easier! If you’d like to sort them by date, ID, @@ -103,7 +103,7 @@ export const postQuery = graphql` } } } -` +`; ``` ## Wrap up and future diff --git a/docs/blog/2017-10-16-making-website-building-fun/index.md b/docs/blog/2017-10-16-making-website-building-fun/index.md index e32c96e8a168e..39c1b573fa664 100644 --- a/docs/blog/2017-10-16-making-website-building-fun/index.md +++ b/docs/blog/2017-10-16-making-website-building-fun/index.md @@ -20,14 +20,14 @@ simple I realized you almost don't need documentation. A React header component using it would look like this: ```jsx -import React from "react" -import Headroom from "react-headroom" +import React from "react"; +import Headroom from "react-headroom"; export default () => (

You can put anything you'd like inside the Headroom Component

-) +); ``` Having coming from years of building things with Backbone.js and jQuery where @@ -49,11 +49,11 @@ Compare this with the minimum code necessary for the original headroom.js. ```js // grab the element -var myElement = document.querySelector("header") +var myElement = document.querySelector("header"); // construct an instance of Headroom, passing the element -var headroom = new Headroom(myElement) +var headroom = new Headroom(myElement); // initialise -headroom.init() +headroom.init(); ``` #### CSS @@ -202,15 +202,15 @@ Here's what a really simple Gatsby page component using gatsby-image would look like: ```jsx -import React from "react" -import Img from "gatsby-image" +import React from "react"; +import Img from "gatsby-image"; export default ({ data }) => (

Hello gatsby-image

-) +); ``` So this is all very nice and it's far better to be able to use this from NPM vs. @@ -248,15 +248,15 @@ The code I showed above was missing the GraphQL query. A full image component would look like: ```jsx -import React from "react" -import Img from "gatsby-image" +import React from "react"; +import Img from "gatsby-image"; export default ({ data }) => (

Hello gatsby-image

-) +); export const query = graphql` query GatsbyImageSampleQuery { @@ -271,7 +271,7 @@ export const query = graphql` } } } -` +`; ``` So instead of a long pipeline of tasks to setup optimized images for your site, diff --git a/docs/blog/2017-10-17-building-i18n-with-gatsby/index.md b/docs/blog/2017-10-17-building-i18n-with-gatsby/index.md index 8794ce0b854e5..7deaf3b757e37 100644 --- a/docs/blog/2017-10-17-building-i18n-with-gatsby/index.md +++ b/docs/blog/2017-10-17-building-i18n-with-gatsby/index.md @@ -83,10 +83,10 @@ but copied here for convenience. You'll need to create an i18n component and import it somewhere (we did it in our index layout): ```jsx -import i18n from "i18next" -import Backend from "i18next-xhr-backend" -import LanguageDetector from "i18next-browser-languagedetector" -import { reactI18nextModule } from "react-i18next" +import i18n from "i18next"; +import Backend from "i18next-xhr-backend"; +import LanguageDetector from "i18next-browser-languagedetector"; +import { reactI18nextModule } from "react-i18next"; i18n .use(Backend) @@ -108,9 +108,9 @@ i18n react: { wait: true, }, - }) + }); -export default i18n +export default i18n; ``` ## Locales @@ -163,16 +163,16 @@ little hook to our `gatsby-node.js` file. It copies the locales folder post build and gets everything in the right place: ```javascript -const fs = require("fs-extra") -const path = require("path") +const fs = require("fs-extra"); +const path = require("path"); exports.onPostBuild = () => { - console.log("Copying locales") + console.log("Copying locales"); fs.copySync( path.join(__dirname, "/src/locales"), path.join(__dirname, "/public/locales") - ) -} + ); +}; ``` ## Using with a component @@ -184,23 +184,23 @@ React-i18next uses a HOC to wrap your component and provide some props to handle language switching. Here's our `PageHeader` component: ```jsx -import React, { Component } from "react" -import { translate } from "react-i18next" +import React, { Component } from "react"; +import { translate } from "react-i18next"; class PageHeader extends Component { render() { - const { t } = this.props + const { t } = this.props; return (

{t("heading")}

{t("description")}

- ) + ); } } -export default translate("PageHeader")(PageHeader) +export default translate("PageHeader")(PageHeader); ``` Pretty simple! The string provided to `translate` is the corresponding JSON file @@ -225,32 +225,32 @@ Finally, to make it easy for our users to switch language we need to create a little component. Here's an example from our site: ```jsx -import React, { Component } from "react" -import classNames from "classnames" -import { translate } from "react-i18next" +import React, { Component } from "react"; +import classNames from "classnames"; +import { translate } from "react-i18next"; class LanguageSwitcher extends Component { constructor(props) { - super(props) - const { i18n } = this.props - this.state = { language: i18n.language } + super(props); + const { i18n } = this.props; + this.state = { language: i18n.language }; - this.handleChangeLanguage = this.handleChangeLanguage.bind(this) + this.handleChangeLanguage = this.handleChangeLanguage.bind(this); } componentWillReceiveProps(nextProps) { - this.setState({ language: nextProps.i18n.language }) + this.setState({ language: nextProps.i18n.language }); } handleChangeLanguage(lng) { - const { i18n } = this.props - i18n.changeLanguage(lng) + const { i18n } = this.props; + i18n.changeLanguage(lng); } renderLanguageChoice({ code, label }) { const buttonClass = classNames("LanguageSwitcher__button", { "LanguageSwitcher__button--selected": this.state.language === code, - }) + }); return ( - ) + ); } render() { const languages = [ { code: "en", label: "English" }, { code: "cy", label: "Cymraeg" }, - ] + ]; return (
{languages.map(language => this.renderLanguageChoice(language))}
- ) + ); } } -export default translate("LanguageSwitcher")(LanguageSwitcher) +export default translate("LanguageSwitcher")(LanguageSwitcher); ``` This is a pretty simple component. We're setting the `language` state based on diff --git a/docs/blog/2017-10-20-from-wordpress-to-developing-in-react-starting-to-see-it/index.md b/docs/blog/2017-10-20-from-wordpress-to-developing-in-react-starting-to-see-it/index.md index 02bb1f50de83f..fef0a2f859a92 100644 --- a/docs/blog/2017-10-20-from-wordpress-to-developing-in-react-starting-to-see-it/index.md +++ b/docs/blog/2017-10-20-from-wordpress-to-developing-in-react-starting-to-see-it/index.md @@ -52,17 +52,17 @@ makes groking easier. I have my layout, template and config modules at hand in the folder structure, without duplication. ```js -import React from "react" +import React from "react"; // Template for blog page export default ({ data }) => { - const post = data.markdownRemark + const post = data.markdownRemark; return (

{post.frontmatter.title}

- ) -} + ); +}; // The data query export const query = graphql` query BlogPostQuery($slug: String!) { @@ -74,7 +74,7 @@ export const query = graphql` } } } -` +`; ``` Whilst this might _look_ weird, it actually makes it much easier to understand @@ -111,7 +111,7 @@ export const query = graphql` } } } -` +`; ``` Aside from those pesky tick characters, which are sometimes hard to spot for a diff --git a/docs/blog/2017-11-06-migrate-hugo-gatsby/index.md b/docs/blog/2017-11-06-migrate-hugo-gatsby/index.md index 7cf34da326cdf..aaf81733b48cc 100644 --- a/docs/blog/2017-11-06-migrate-hugo-gatsby/index.md +++ b/docs/blog/2017-11-06-migrate-hugo-gatsby/index.md @@ -98,7 +98,7 @@ This might sound way more complicated than what it is: ```jsx exports.createPages = ({ graphql, boundActionCreators }) => { - const { createPage } = boundActionCreators + const { createPage } = boundActionCreators; graphql(` { allMarkdownRemark { @@ -114,10 +114,10 @@ exports.createPages = ({ graphql, boundActionCreators }) => { } } `).then(result => { - const posts = result.data.allMarkdownRemark.edges + const posts = result.data.allMarkdownRemark.edges; // Create content programatically here - }) -} + }); +}; ``` As you see, getting the list of posts can be done in a single query. @@ -127,10 +127,10 @@ prefer to keep in a separate module. For example, creating posts works like following: ```jsx -const path = require(`path`) +const path = require(`path`); module.exports = (createPage, nodes) => { - const template = path.resolve(`src/templates/post.js`) + const template = path.resolve(`src/templates/post.js`); nodes.map(({ node }) => { if (node.frontmatter.slug) { @@ -140,10 +140,10 @@ module.exports = (createPage, nodes) => { context: { slug: node.frontmatter.slug, }, - }) + }); } - }) -} + }); +}; ``` I re-use the `slug` field of the frontmatter of my existing structure. I don't @@ -233,12 +233,12 @@ both tags and pagination scenarios. I kept them as separate action creators and I just called them in the main creator function like this: ```jsx -const createPostPages = require(`./gatsby-actions/createPostPages`) -const createPaginatedPostsPages = require(`./gatsby-actions/createPaginatedPostsPages`) -const createTagPages = require(`./gatsby-actions/createTagPages`) +const createPostPages = require(`./gatsby-actions/createPostPages`); +const createPaginatedPostsPages = require(`./gatsby-actions/createPaginatedPostsPages`); +const createTagPages = require(`./gatsby-actions/createTagPages`); exports.createPages = ({ graphql, boundActionCreators }) => { - const { createPage } = boundActionCreators + const { createPage } = boundActionCreators; graphql(` { allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) { @@ -254,41 +254,41 @@ exports.createPages = ({ graphql, boundActionCreators }) => { } } `).then(result => { - const posts = result.data.allMarkdownRemark.edges - createPostPages(createPage, posts) - createPaginatedPostsPages(createPage, posts) - createTagPages(createPage, posts) - }) -} + const posts = result.data.allMarkdownRemark.edges; + createPostPages(createPage, posts); + createPaginatedPostsPages(createPage, posts); + createTagPages(createPage, posts); + }); +}; ``` Easy to read, understand and mantain. The pagination module is a bit longer than the one of the posts: ```jsx -const path = require(`path`) +const path = require(`path`); module.exports = (createPage, nodes) => { - const template = path.resolve(`src/templates/postList.js`) - const paginateSize = 10 + const template = path.resolve(`src/templates/postList.js`); + const paginateSize = 10; // Split posts into arrays of length equal to number posts on each page/paginateSize const groupedPages = nodes .map((node, index) => { return index % paginateSize === 0 ? nodes.slice(index, index + paginateSize) - : null + : null; }) - .filter(item => item) + .filter(item => item); // Create new indexed route for each array groupedPages.forEach((group, index, groups) => { - const pageIndex = index === 0 ? `` : index + 1 - const paginationRoute = `/blog/${pageIndex}` + const pageIndex = index === 0 ? `` : index + 1; + const paginationRoute = `/blog/${pageIndex}`; // Avoid showing `Previous` link on first page - passed to context - const first = index === 0 ? true : false + const first = index === 0 ? true : false; // Avoid showing `Next` link if this is the last page - passed to context - const last = index === groups.length - 1 ? true : false + const last = index === groups.length - 1 ? true : false; return createPage({ path: paginationRoute, @@ -299,9 +299,9 @@ module.exports = (createPage, nodes) => { last, index: index + 1, }, - }) - }) -} + }); + }); +}; ``` Then, pull context information in the React component: @@ -358,7 +358,7 @@ createPage({ context: { posts, }, -}) +}); ``` For the inner tag page: @@ -372,7 +372,7 @@ createPage({ post, tag: tagName, }, -}) +}); ``` ### Admin panel @@ -425,8 +425,8 @@ This is my admin page React component which is placed in `src/pages/admin` so that Gatsby delivers the HTML page at `/admin`. ```jsx -import React from "react" -import Helmet from "react-helmet" +import React from "react"; +import Helmet from "react-helmet"; const AdminPage = () => (
@@ -446,9 +446,9 @@ const AdminPage = () => ( />
-) +); -export default AdminPage +export default AdminPage; ``` In order for NetlifyCMS script to find the configuration file correctly, diff --git a/docs/blog/2017-11-08-migrate-from-jekyll-to-gatsby/index.md b/docs/blog/2017-11-08-migrate-from-jekyll-to-gatsby/index.md index da28fb4da1eb9..011e9b5e6df00 100644 --- a/docs/blog/2017-11-08-migrate-from-jekyll-to-gatsby/index.md +++ b/docs/blog/2017-11-08-migrate-from-jekyll-to-gatsby/index.md @@ -44,7 +44,7 @@ matter block, so you don't have to change anything. You just need to install Then, in your `gatsby-config.js` file add: ```js -plugins: ["gatsby-transformer-remark"] +plugins: ["gatsby-transformer-remark"]; ``` ### Theme @@ -88,30 +88,30 @@ extension API to tweak the slug: ```js exports.onCreateNode = ({ node, getNode, boundActionCreators }) => { - const { createNodeField } = boundActionCreators + const { createNodeField } = boundActionCreators; if (node.internal.type === `MarkdownRemark`) { - const { categories } = node.frontmatter + const { categories } = node.frontmatter; - const filename = createFilePath({ node, getNode, basePath: `pages` }) + const filename = createFilePath({ node, getNode, basePath: `pages` }); // get the date and title from the file name const [, date, title] = filename.match( /^\/([\d]{4}-[\d]{2}-[\d]{2})-{1}(.+)\/$/ - ) + ); // create a new slug concatenating everything const slug = `/${slugify( categories.concat([date]).join("-"), "/" - )}/${title}/` + )}/${title}/`; - createNodeField({ node, name: `slug`, value: slug }) + createNodeField({ node, name: `slug`, value: slug }); // save the date for later use - createNodeField({ node, name: `date`, value: date }) + createNodeField({ node, name: `date`, value: date }); } -} +}; ``` ### Deploy diff --git a/docs/blog/gatsby-v1.md b/docs/blog/gatsby-v1.md index 43f7cdbe5bfad..7b11267508a61 100644 --- a/docs/blog/gatsby-v1.md +++ b/docs/blog/gatsby-v1.md @@ -162,7 +162,7 @@ the blog posts. Included with the component is an exported `pageQuery`. ```jsx // A simple React component for rendering a blog page. -import React from "react" +import React from "react"; class BlogPostTemplate extends React.Component { render() { @@ -176,11 +176,11 @@ class BlogPostTemplate extends React.Component { }} />
- ) + ); } } -export default BlogPostTemplate +export default BlogPostTemplate; export const pageQuery = graphql` query BlogPost($slug: String!) { @@ -194,7 +194,7 @@ export const pageQuery = graphql` } } } -` +`; ``` All data sourcing and transforming is plugin-driven. So in time, any imaginable @@ -276,8 +276,8 @@ you navigate around, Gatsby loads in the code needed for each route. This means that one page with heavy imports: ```javascript -import d3 from "d3" -import threejs from "react-threejs" +import d3 from "d3"; +import threejs from "react-threejs"; ``` ...won't affect the performance of the rest of the site. diff --git a/docs/blog/gatsbygram-case-study/index.md b/docs/blog/gatsbygram-case-study/index.md index 7b0424b34f0e5..85ccbadde83fe 100644 --- a/docs/blog/gatsbygram-case-study/index.md +++ b/docs/blog/gatsbygram-case-study/index.md @@ -149,18 +149,18 @@ the site's [`gatsby-node.js` file](https://github.com/gatsbyjs/gatsby/blob/master/examples/gatsbygram/gatsby-node.js): ```javascript -const _ = require(`lodash`) -const Promise = require(`bluebird`) -const path = require(`path`) -const slug = require(`slug`) -const slash = require(`slash`) +const _ = require(`lodash`); +const Promise = require(`bluebird`); +const path = require(`path`); +const slug = require(`slug`); +const slash = require(`slash`); // Implement the Gatsby API “createPages”. This is // called after the Gatsby bootstrap is finished so you have // access to any information necessary to programmatically // create pages. exports.createPages = ({ graphql, boundActionCreators }) => { - const { createPage } = boundActionCreators + const { createPage } = boundActionCreators; return new Promise((resolve, reject) => { // The “graphql” function allows us to run arbitrary @@ -188,11 +188,11 @@ exports.createPages = ({ graphql, boundActionCreators }) => { ` ).then(result => { if (result.errors) { - reject(new Error(result.errors)) + reject(new Error(result.errors)); } // Create image post pages. - const postTemplate = path.resolve(`src/templates/post-page.js`) + const postTemplate = path.resolve(`src/templates/post-page.js`); // We want to create a detailed page for each // Instagram post. Since the scrapped Instagram data // already includes an ID field, we just use that for @@ -211,14 +211,14 @@ exports.createPages = ({ graphql, boundActionCreators }) => { context: { id: edge.node.id, }, - }) - }) + }); + }); - return + return; }) - ) - }) -} + ); + }); +}; ``` ## Using templates @@ -237,8 +237,8 @@ we pass the id to the post. Below we use that id to query our `GraphQL` schema and return a fully formed page: ```jsx -import React from "react" -import PostDetail from "../components/post-detail" +import React from "react"; +import PostDetail from "../components/post-detail"; class PostTemplate extends React.Component { render() { @@ -246,11 +246,11 @@ class PostTemplate extends React.Component { // PostDetail is used for this detail page and // also in the modal. - ) + ); } } -export default PostTemplate +export default PostTemplate; // The post template's GraphQL query. Notice the “id” // variable which is passed in. We set this on the page @@ -291,7 +291,7 @@ export const pageQuery = ` } } } -` +`; ``` ## Creating React.js component pages @@ -328,8 +328,8 @@ loading your site from a service worker. A simple layout component might look something like this. ```jsx -import React from "react" -import Link from "gatsby-link" +import React from "react"; +import Link from "gatsby-link"; class Layout extends React.Component { render() { @@ -340,19 +340,19 @@ class Layout extends React.Component { {/* Render children pages */} {this.props.children()} - ) + ); } } -export default Layout +export default Layout; ``` Every page will be rendered as children of the `Layout` component: ```jsx -; + - +; ``` Gatsbygram's layout component is somewhat more complicated than most sites as it @@ -459,7 +459,7 @@ module.exports = { }, }, ], -} +}; ``` ## Styles diff --git a/docs/docs/add-custom-webpack-config.md b/docs/docs/add-custom-webpack-config.md index dfbf299f9c34e..89183dc792fef 100644 --- a/docs/docs/add-custom-webpack-config.md +++ b/docs/docs/add-custom-webpack-config.md @@ -47,32 +47,32 @@ exports.modifyWebpackConfig = ({ config, stage }) => { case "develop": config.loader("css", { include: /flexboxgrid/, - }) + }); - break + break; case "build-css": config.loader("css", { include: /flexboxgrid/, - }) + }); - break + break; case "build-html": config.loader("css", { include: /flexboxgrid/, - }) + }); - break + break; case "build-javascript": config.loader("css", { include: /flexboxgrid/, - }) + }); - break + break; } - return config -} + return config; +}; ``` diff --git a/docs/docs/adding-images-fonts-files.md b/docs/docs/adding-images-fonts-files.md index ccac6258fd52a..52262619588e4 100644 --- a/docs/docs/adding-images-fonts-files.md +++ b/docs/docs/adding-images-fonts-files.md @@ -17,17 +17,17 @@ jpeg, png, gif, mp4, webm, wav, mp3, m4a, aac, and oga. Here is an example: ```js -import React from "react" -import logo from "./logo.png" // Tell Webpack this JS file uses this image +import React from "react"; +import logo from "./logo.png"; // Tell Webpack this JS file uses this image -console.log(logo) // /logo.84287d09.png +console.log(logo); // /logo.84287d09.png function Header() { // Import result is the URL of your image - return Logo + return Logo; } -export default Header +export default Header; ``` This ensures that when the project is built, Webpack will correctly move the diff --git a/docs/docs/api-proxy.md b/docs/docs/api-proxy.md index 2cd3a1ab94075..def7fcbd17226 100644 --- a/docs/docs/api-proxy.md +++ b/docs/docs/api-proxy.md @@ -14,7 +14,7 @@ module.exports = { prefix: "/api", url: "http://dev-mysite.com/api/", }, -} +}; ``` This way, when you `fetch('/api/todos')` in development, the development server diff --git a/docs/docs/building-with-components.md b/docs/docs/building-with-components.md index 73375319cad74..23f1867c52abc 100644 --- a/docs/docs/building-with-components.md +++ b/docs/docs/building-with-components.md @@ -61,20 +61,20 @@ Example: `src/pages/about.jsx` ```jsx -import React, { Component } from "react" +import React, { Component } from "react"; class AboutPage extends Component { render() { - const config = this.props.data.site.siteMetadata + const config = this.props.data.site.siteMetadata; return (

About me.

- ) + ); } } -export default AboutPage +export default AboutPage; ``` ### Page template components @@ -92,22 +92,22 @@ introduction to programmatically creating pages. Example: ```jsx -import React from "react" +import React from "react"; class BlogPostTemplate extends React.Component { render() { - const post = this.props.data.markdownRemark + const post = this.props.data.markdownRemark; return (

{post.frontmatter.title}

- ) + ); } } -export default BlogPostTemplate +export default BlogPostTemplate; export const pageQuery = graphql` query BlogPostBySlug($slug: String!) { @@ -118,7 +118,7 @@ export const pageQuery = graphql` } } } -` +`; ``` ### Layout components @@ -129,12 +129,12 @@ portions of pages that are shared across pages like headers and footers. Example: ```jsx -import React from "react" -import Navigation from "../components/Navigation/Navigation.jsx" +import React from "react"; +import Navigation from "../components/Navigation/Navigation.jsx"; export default class Template extends React.Component { render() { - return {this.props.children()} + return {this.props.children()}; } } ``` @@ -154,28 +154,28 @@ have an html.js. Example: ```jsx -import React from "react" -import favicon from "./favicon.png" +import React from "react"; +import favicon from "./favicon.png"; -let inlinedStyles = "" +let inlinedStyles = ""; if (process.env.NODE_ENV === "production") { try { - inlinedStyles = require("!raw-loader!../public/styles.css") + inlinedStyles = require("!raw-loader!../public/styles.css"); } catch (e) { - console.log(e) + console.log(e); } } export default class HTML extends React.Component { render() { - let css + let css; if (process.env.NODE_ENV === "production") { css = (