Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

www: move dotenv to gatsby-config so it can be used with GATSBY_SCREENSHOT_PLACEHOLDER #9851

Merged
merged 3 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions docs/docs/programmatically-create-pages-from-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ which is at the core of programmatically creating a page.

```javascript{17-25}:title=gatsby-node.js
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
const { createPage } = actions
return new Promise((resolve, reject) => {
graphql(`
{
Expand All @@ -45,12 +45,12 @@ exports.createPages = ({ graphql, actions }) => {
context: {
slug: node.fields.slug,
},
});
});
resolve();
});
});
};
})
})
resolve()
})
})
}
```

For each page we want to create we must specify the `path` for visiting that
Expand All @@ -66,23 +66,21 @@ that will be used to render the page. Here is an example of what the
referenced template could look like:

```javascript:title=gatsby-node.js
import React from 'react';
import { graphql } from 'gatsby';
import Layout from '../components/layout';
import React from "react"
import { graphql } from "gatsby"
import Layout from "../components/layout"

export default ({ data }) => {
const post = data.markdownRemark;
const post = data.markdownRemark
return (
<Layout>
<div>
<h1>
{post.frontmatter.title}
</h1>
<h1>{post.frontmatter.title}</h1>
<div dangerouslySetInnerHTML={{ __html: post.html }} />
</div>
</Layout>
);
};
)
}

export const query = graphql`
query($slug: String!) {
Expand All @@ -93,7 +91,7 @@ export const query = graphql`
}
}
}
`;
`
```

Notice that the `slug` value we specified in the `createPage` context is
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-screenshot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ You can use placeholder image by setting `GATSBY_SCREENSHOT_PLACEHOLDER` environ
GATSBY_SCREENSHOT_PLACEHOLDER=true gatsby develop
```

or by adding it to `.env.development` file in root of your project:
or by using [`dotenv`](https://www.gatsbyjs.org/docs/environment-variables/#server-side-nodejs) in your `gatsby-config.js` and adding `GATSBY_SCREENSHOT_PLACEHOLDER` to `.env.development` file in root of your project:

```shell:title=.env.development
GATSBY_SCREENSHOT_PLACEHOLDER=true
Expand Down
4 changes: 4 additions & 0 deletions www/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require(`dotenv`).config({
path: `.env.${process.env.NODE_ENV}`,
})

module.exports = {
siteMetadata: {
title: `GatsbyJS`,
Expand Down
4 changes: 0 additions & 4 deletions www/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ const moment = require(`moment`)

let ecosystemFeaturedItems

require(`dotenv`).config({
path: `.env.${process.env.NODE_ENV}`,
})

if (
process.env.gatsby_executing_command === `build` &&
!process.env.GITHUB_API_TOKEN
Expand Down