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

docs(gatsby): improve createPages example #10777

Merged
merged 2 commits into from
Jan 2, 2019
Merged
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
70 changes: 35 additions & 35 deletions packages/gatsby/src/utils/api-node-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,49 @@ exports.resolvableExtensions = true
*
* See also [the documentation for the action `createPage`](/docs/actions/#createPage).
* @example
* const path = require(`path`)
*
* exports.createPages = ({ graphql, actions }) => {
* const { createPage } = actions
* return new Promise((resolve, reject) => {
* const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
* // Query for markdown nodes to use in creating pages.
* resolve(
* graphql(
* `
* {
* allMarkdownRemark(limit: 1000) {
* edges {
* node {
* fields {
* slug
* }
* const blogPostTemplate = path.resolve(`src/templates/blog-post.js`)
* // Query for markdown nodes to use in creating pages.
* // You can query for whatever data you want to create pages for e.g.
* // products, portfolio items, landing pages, etc.
* return graphql(`
* {
* allMarkdownRemark(limit: 1000) {
* edges {
* node {
* fields {
* slug
* }
* }
* }
* }
* `
* ).then(result => {
* if (result.errors) {
* reject(result.errors)
* }
*
* // Create blog post pages.
* result.data.allMarkdownRemark.edges.forEach(edge => {
* createPage({
* path: `${edge.node.fields.slug}`, // required
* component: blogPostTemplate,
* context: {
* // Add optional context data. Data can be used as
* // arguments to the page GraphQL query.
* //
* // The page "path" is always available as a GraphQL
* // argument.
* },
* })
* })
* }
* `).then(result => {
* if (result.errors) {
* throw result.errors
* }
*
* return
* // Create blog post pages.
* result.data.allMarkdownRemark.edges.forEach(edge => {
* createPage({
* // Path for this page — required
* path: `${edge.node.fields.slug}`,
* component: blogPostTemplate,
* context: {
* // Add optional context data to be inserted
* // as props into the page component..
* //
* // The context data can also be used as
* // arguments to the page GraphQL query.
* //
* // The page "path" is always available as a GraphQL
* // argument.
* },
* })
* )
* })
* })
* }
*/
Expand Down