-
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Option to make tables separate node types (#52) * Option to make tables separate node types * Revert "Option to make tables separate node types" This reverts commit b59ffda. * Removed package/lock from branch * Added AirtableField node types. * Added more info for createSeparateNodeType * Version bump * Check that separateNodeType option exists * add option to set mapping fields each as a separate type (#115) * separateMapTypes config option * update version * Feat/multi node types/parent node field (#144) * prettier all the things * add separateNodeType option * spelling mistake * add separateNodeType * add example that errors without new features * bump version number Co-authored-by: Kevin Miller <[email protected]>
- Loading branch information
Showing
16 changed files
with
31,438 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
module.exports = { | ||
siteMetadata: { | ||
title: "Gatsby Recipes" | ||
}, | ||
plugins: [ | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `pages`, | ||
path: `${__dirname}/src/pages/` | ||
} | ||
}, | ||
{ | ||
resolve: `gatsby-source-filesystem`, | ||
options: { | ||
name: `assets`, | ||
path: `${__dirname}/src/assets/` | ||
} | ||
}, | ||
{ | ||
resolve: `gatsby-source-airtable`, | ||
options: { | ||
apiKey: process.env.AIRTABLE_API_KEY_DEV, //(set via environment variable for this example) | ||
tables: [ | ||
{ | ||
baseId: `appM8D8wmSJX9WJDE`, | ||
tableName: `Recipes`, | ||
queryName: `Recipes`, | ||
tableView: `List`, | ||
mapping: { | ||
Attachments: `fileNode`, | ||
Ingredients: "text/markdown", | ||
Directions: "text/markdown" | ||
}, | ||
tableLinks: [`Cooking_Method`, `Style`], | ||
separateNodeType: true, | ||
separateMapType: true | ||
}, | ||
{ | ||
baseId: `appM8D8wmSJX9WJDE`, | ||
tableName: `Cooking Method`, | ||
tableView: `Main View`, | ||
tableLinks: [`Recipes`] | ||
}, | ||
{ | ||
baseId: `appM8D8wmSJX9WJDE`, | ||
tableName: `Style`, | ||
tableView: `Main View`, | ||
tableLinks: [`Recipes`] | ||
} | ||
] | ||
} | ||
}, | ||
`gatsby-plugin-sharp`, | ||
`gatsby-transformer-sharp`, | ||
`gatsby-plugin-mdx`, | ||
`gatsby-plugin-react-helmet` | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
const path = require(`path`); | ||
|
||
exports.onCreateNode = ({ node, actions, getNode }) => { | ||
const { createNodeField } = actions; | ||
let slug; | ||
|
||
if (node.internal.type === `AirtableRecipes` && node.table === `Recipes`) { | ||
slug = `/${node.data.Name.replace(/ /g, "-") | ||
.replace(/[,&]/g, "") | ||
.toLowerCase()}/`; | ||
|
||
// Add slug as a field on the node. | ||
createNodeField({ node, name: `slug`, value: slug }); | ||
} | ||
}; | ||
|
||
exports.createPages = ({ graphql, actions }) => { | ||
const { createPage, createRedirect } = actions; | ||
|
||
return new Promise((resolve, reject) => { | ||
const pages = []; | ||
const atRecipes = path.resolve(`src/templates/recipeTemplate.js`); | ||
|
||
// Query for all markdown "nodes" and for the slug we previously created. | ||
resolve( | ||
graphql( | ||
` | ||
{ | ||
allAirtableRecipes(filter: { table: { eq: "Recipes" } }) { | ||
edges { | ||
node { | ||
id | ||
data { | ||
Name | ||
} | ||
fields { | ||
slug | ||
} | ||
} | ||
} | ||
} | ||
} | ||
` | ||
).then(result => { | ||
if (result.errors) { | ||
result.errors.forEach(error => { | ||
console.log(error); | ||
}); | ||
|
||
reject(result.errors); | ||
} | ||
|
||
result.data.allAirtableRecipes.edges.forEach(edge => { | ||
createPage({ | ||
path: edge.node.fields.slug, // required, we don't have frontmatter for this page hence separate if() | ||
component: atRecipes, | ||
context: { | ||
name: edge.node.data.Name | ||
} | ||
}); | ||
}); | ||
|
||
return; | ||
}) | ||
); | ||
}); | ||
}; |
Oops, something went wrong.