Skip to content

Commit 060661f

Browse files
KyleAMathewsDSchau
authored andcommitted
docs(gatsby): improve createPages example (#10777)
<!-- Have any questions? Check out the contributing docs at https://gatsby.app/contribute, or ask in this Pull Request and a Gatsby maintainer will be happy to help :) --> <!-- Write a brief description of the changes introduced by this PR --> <!-- Link to the issue that is fixed by this PR (if there is one) e.g. Fixes #1234, Addresses #1234, Related to #1234, etc. -->
1 parent 49c9324 commit 060661f

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

packages/gatsby/src/utils/api-node-docs.js

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,49 @@ exports.resolvableExtensions = true
1212
*
1313
* See also [the documentation for the action `createPage`](/docs/actions/#createPage).
1414
* @example
15+
* const path = require(`path`)
16+
*
1517
* exports.createPages = ({ graphql, actions }) => {
1618
* const { createPage } = actions
17-
* return new Promise((resolve, reject) => {
18-
* const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
19-
* // Query for markdown nodes to use in creating pages.
20-
* resolve(
21-
* graphql(
22-
* `
23-
* {
24-
* allMarkdownRemark(limit: 1000) {
25-
* edges {
26-
* node {
27-
* fields {
28-
* slug
29-
* }
19+
* const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
20+
* // Query for markdown nodes to use in creating pages.
21+
* // You can query for whatever data you want to create pages for e.g.
22+
* // products, portfolio items, landing pages, etc.
23+
* return graphql(`
24+
* {
25+
* allMarkdownRemark(limit: 1000) {
26+
* edges {
27+
* node {
28+
* fields {
29+
* slug
3030
* }
3131
* }
3232
* }
3333
* }
34-
* `
35-
* ).then(result => {
36-
* if (result.errors) {
37-
* reject(result.errors)
38-
* }
39-
*
40-
* // Create blog post pages.
41-
* result.data.allMarkdownRemark.edges.forEach(edge => {
42-
* createPage({
43-
* path: `${edge.node.fields.slug}`, // required
44-
* component: blogPostTemplate,
45-
* context: {
46-
* // Add optional context data. Data can be used as
47-
* // arguments to the page GraphQL query.
48-
* //
49-
* // The page "path" is always available as a GraphQL
50-
* // argument.
51-
* },
52-
* })
53-
* })
34+
* }
35+
* `).then(result => {
36+
* if (result.errors) {
37+
* throw result.errors
38+
* }
5439
*
55-
* return
40+
* // Create blog post pages.
41+
* result.data.allMarkdownRemark.edges.forEach(edge => {
42+
* createPage({
43+
* // Path for this page — required
44+
* path: `${edge.node.fields.slug}`,
45+
* component: blogPostTemplate,
46+
* context: {
47+
* // Add optional context data to be inserted
48+
* // as props into the page component..
49+
* //
50+
* // The context data can also be used as
51+
* // arguments to the page GraphQL query.
52+
* //
53+
* // The page "path" is always available as a GraphQL
54+
* // argument.
55+
* },
5656
* })
57-
* )
57+
* })
5858
* })
5959
* }
6060
*/

0 commit comments

Comments
 (0)