From b7cbef95abf0a7cb98748571a784ee69e1a93b59 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Tue, 20 Oct 2020 14:21:32 +0200 Subject: [PATCH] Drop changes in /benchmarks, fix typo --- benchmarks/gabe-csv-markdown/gatsby-node.js | 31 +++--- benchmarks/markdown_id/gatsby-node.js | 23 ++--- benchmarks/markdown_slug/gatsby-node.js | 23 ++--- benchmarks/md/gatsby-node.js | 32 +++---- benchmarks/mdx/gatsby-node.js | 18 ++-- benchmarks/source-agilitycms/gatsby-node.js | 100 +++++++++----------- benchmarks/source-cosmicjs/gatsby-node.js | 14 +-- benchmarks/source-datocms/gatsby-node.js | 8 +- benchmarks/source-drupal/gatsby-node.js | 8 +- benchmarks/source-flotiq/gatsby-node.js | 8 +- packages/gatsby-plugin-mdx/gatsby-node.js | 2 +- 11 files changed, 105 insertions(+), 162 deletions(-) diff --git a/benchmarks/gabe-csv-markdown/gatsby-node.js b/benchmarks/gabe-csv-markdown/gatsby-node.js index 689f0607142fd..e175aa95b70f4 100644 --- a/benchmarks/gabe-csv-markdown/gatsby-node.js +++ b/benchmarks/gabe-csv-markdown/gatsby-node.js @@ -42,26 +42,21 @@ exports.createPages = async ({ graphql, actions }) => { }) } -function unstable_shouldOnCreateNode({ node }) { - return node.internal.type === `GendataCsv` -} - // Not sure if there is a better way than to create a proxy node for markdown to pick up // I certainly can't get remark to to pick up csv nodes :( -function onCreateNode({ node, actions }) { +exports.onCreateNode = ({ node, actions }) => { const { createNode } = actions - createNode({ - id: `${node.id}-MarkdownProxy`, - parent: node.id, - internal: { - type: `MarkdownProxy`, - mediaType: "text/markdown", - content: node.articleContent, - contentDigest: node.articleContent, - }, - }) + if (node.internal.type === `GendataCsv`) { + createNode({ + id: `${node.id}-MarkdownProxy`, + parent: node.id, + internal: { + type: `MarkdownProxy`, + mediaType: "text/markdown", + content: node.articleContent, + contentDigest: node.articleContent, + }, + }) + } } - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode -exports.onCreateNode = onCreateNode diff --git a/benchmarks/markdown_id/gatsby-node.js b/benchmarks/markdown_id/gatsby-node.js index 268c09adf7a38..40a81a43188ce 100644 --- a/benchmarks/markdown_id/gatsby-node.js +++ b/benchmarks/markdown_id/gatsby-node.js @@ -48,20 +48,15 @@ exports.createPages = async ({ graphql, actions }) => { }) } -function unstable_shouldOnCreateNode({ node }) { - return node.internal.type === `MarkdownRemark` -} - -function onCreateNode({ node, actions, getNode }) { +exports.onCreateNode = ({ node, actions, getNode }) => { const { createNodeField } = actions - const value = createFilePath({ node, getNode }) - createNodeField({ - name: `slug`, - node, - value, - }) + if (node.internal.type === `MarkdownRemark`) { + const value = createFilePath({ node, getNode }) + createNodeField({ + name: `slug`, + node, + value, + }) + } } - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode -exports.onCreateNode = onCreateNode diff --git a/benchmarks/markdown_slug/gatsby-node.js b/benchmarks/markdown_slug/gatsby-node.js index 216953ccd0661..8c980141d3a5b 100644 --- a/benchmarks/markdown_slug/gatsby-node.js +++ b/benchmarks/markdown_slug/gatsby-node.js @@ -47,20 +47,15 @@ exports.createPages = async ({ graphql, actions }) => { }) } -function unstable_shouldOnCreateNode({ node }) { - return node.internal.type === `MarkdownRemark` -} - -function onCreateNode({ node, actions, getNode }) { +exports.onCreateNode = ({ node, actions, getNode }) => { const { createNodeField } = actions - const value = createFilePath({ node, getNode }) - createNodeField({ - name: `slug`, - node, - value, - }) + if (node.internal.type === `MarkdownRemark`) { + const value = createFilePath({ node, getNode }) + createNodeField({ + name: `slug`, + node, + value, + }) + } } - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode -exports.onCreateNode = onCreateNode diff --git a/benchmarks/md/gatsby-node.js b/benchmarks/md/gatsby-node.js index 15efb43402ec2..4855458bd3b53 100644 --- a/benchmarks/md/gatsby-node.js +++ b/benchmarks/md/gatsby-node.js @@ -1,6 +1,20 @@ const path = require("path") const { createFilePath } = require("gatsby-source-filesystem") +exports.onCreateNode = ({ node, actions, getNode }) => { + const { createNodeField } = actions + + if (node.internal.type === "MarkdownRemark") { + const value = createFilePath({ node, getNode }) + + createNodeField({ + name: "path", + node, + value, + }) + } +} + exports.createPages = async ({ graphql, actions, reporter }) => { const { createPage } = actions @@ -33,21 +47,3 @@ exports.createPages = async ({ graphql, actions, reporter }) => { }) }) } - -function unstable_shouldOnCreateNode({ node }) { - return node.internal.type === `MarkdownRemark` -} - -function onCreateNode({ node, actions, getNode }) { - const { createNodeField } = actions - - const value = createFilePath({ node, getNode }) - createNodeField({ - name: `path`, - node, - value, - }) -} - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode -exports.onCreateNode = onCreateNode diff --git a/benchmarks/mdx/gatsby-node.js b/benchmarks/mdx/gatsby-node.js index 5b013e69efb03..1388e4c84e7e6 100644 --- a/benchmarks/mdx/gatsby-node.js +++ b/benchmarks/mdx/gatsby-node.js @@ -1,20 +1,18 @@ const path = require("path") const { createFilePath } = require("gatsby-source-filesystem") -exports.unstable_shouldOnCreateNode = function ({ node }) { - return node.internal.type === "Mdx" -} - exports.onCreateNode = ({ node, actions, getNode }) => { const { createNodeField } = actions - const value = createFilePath({ node, getNode }) + if (node.internal.type === "Mdx") { + const value = createFilePath({ node, getNode }) - createNodeField({ - name: "path", - node, - value, - }) + createNodeField({ + name: "path", + node, + value, + }) + } } exports.createPages = async ({ graphql, actions, reporter }) => { diff --git a/benchmarks/source-agilitycms/gatsby-node.js b/benchmarks/source-agilitycms/gatsby-node.js index 70748d6705f90..86648f9fb6261 100644 --- a/benchmarks/source-agilitycms/gatsby-node.js +++ b/benchmarks/source-agilitycms/gatsby-node.js @@ -1,69 +1,57 @@ -const agility = require("./src/agility/utils") +const agility = require('./src/agility/utils') const { createRemoteFileNode } = require("gatsby-source-filesystem") //gatsy-node.js //CREATE RESOLVERS ******************************************************************************************* exports.createResolvers = (args) => { - const { - createResolvers, - getNode, - createNodeId, - createNode, - createContentDigest, - configOptions, - } = args - const resolvers = { - //on the 'agilityPost' node type... - agilityPost: { - //get the sitemap node that represents this item - useful for retrieving the URL for the item - sitemapNode: agility.getDynamicPageItemSitemapNode(), + const { createResolvers, getNode, createNodeId, createNode, createContentDigest, configOptions } = args; - //[Not Implemented] - //if we had a linked content field for 'author', this is how we'd get the author for this post in a single GraphQl query - //linkedContent_agilityAuthor: agility.getLinkedContentItem({ type: 'agilityAuthor', linkedContentFieldName: 'author' }) - }, + const resolvers = { + //on the 'agilityPost' node type... + agilityPost: { + //get the sitemap node that represents this item - useful for retrieving the URL for the item + sitemapNode: agility.getDynamicPageItemSitemapNode(), - //[Not Implemented] - //if we had an 'Image Slider' module and it had a list of slides via a linked content field called 'slides', this is how we'd retrieve a list of those slides in a single GraphQL query - // agilityImageSlider: { - // linkedContent_agilitySlides: agility.getLinkedContentList({ type: 'agilitySlide', linkedContentFieldName: 'slides' }) - // } - } - createResolvers(resolvers) -} + //[Not Implemented] + //if we had a linked content field for 'author', this is how we'd get the author for this post in a single GraphQl query + //linkedContent_agilityAuthor: agility.getLinkedContentItem({ type: 'agilityAuthor', linkedContentFieldName: 'author' }) + }, -function unstable_shouldOnCreateNode({node}) { - return ( - node.properties && node.properties.referenceName.toLowerCase() === `posts` - ) + //[Not Implemented] + //if we had an 'Image Slider' module and it had a list of slides via a linked content field called 'slides', this is how we'd retrieve a list of those slides in a single GraphQL query + // agilityImageSlider: { + // linkedContent_agilitySlides: agility.getLinkedContentList({ type: 'agilitySlide', linkedContentFieldName: 'slides' }) + // } + } + createResolvers(resolvers) } -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode - exports.onCreateNode = async ({ - node, - actions: { createNode }, - store, - cache, - createNodeId, + node, + actions: { createNode }, + store, + cache, + createNodeId, }) => { - if (unstable_shouldOnCreateNode({node})) { - let field = "image" - let imageUrl = node.customFields[field] - if (imageUrl) { - let fileNode = await createRemoteFileNode({ - url: imageUrl, // string that points to the URL of the image - parentNodeId: node.id, // id of the parent node of the fileNode you are going to create - createNode, // helper function in gatsby-node to generate the node - createNodeId, // helper function in gatsby-node to generate the node id - cache, // Gatsby's cache - store, // Gatsby's redux store - }) - // if the file was created, attach the new node to the parent node - if (fileNode) { - node.customFields[`${field}LocalImg___NODE`] = fileNode.id - } - } - } -} + + if (node.properties + && node.properties.referenceName.toLowerCase() === `posts`) { + let field = "image" + let imageUrl = node.customFields[field] + if (imageUrl) { + let fileNode = await createRemoteFileNode({ + url: imageUrl, // string that points to the URL of the image + parentNodeId: node.id, // id of the parent node of the fileNode you are going to create + createNode, // helper function in gatsby-node to generate the node + createNodeId, // helper function in gatsby-node to generate the node id + cache, // Gatsby's cache + store, // Gatsby's redux store + }) + // if the file was created, attach the new node to the parent node + if (fileNode) { + node.customFields[`${field}LocalImg___NODE`] = fileNode.id + } + } + } +} \ No newline at end of file diff --git a/benchmarks/source-cosmicjs/gatsby-node.js b/benchmarks/source-cosmicjs/gatsby-node.js index 4912615a66686..40ab25a22e39b 100644 --- a/benchmarks/source-cosmicjs/gatsby-node.js +++ b/benchmarks/source-cosmicjs/gatsby-node.js @@ -1,15 +1,9 @@ const kebabCase = require(`lodash.kebabcase`) -function unstable_shouldOnCreateNode({node}) { - return node.internal.type === "node__article" -} - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode - exports.onCreateNode = ({ actions, node }) => { const { createNodeField } = actions - if (unstable_shouldOnCreateNode({node})) { + if (node.internal.type === 'node__article') { createNodeField({ node, name: "slug", value: kebabCase(node.title) }) } } @@ -33,13 +27,13 @@ exports.createPages = async ({ actions, graphql, reporter }) => { reporter.panicOnBuild(result.errors) } - result.data.articles.edges.map((article) => { + result.data.articles.edges.map(article => { createPage({ path: article.node.slug, component: require.resolve(`./src/templates/article.js`), context: { slug: article.node.slug, - }, + } }) }) -} +} \ No newline at end of file diff --git a/benchmarks/source-datocms/gatsby-node.js b/benchmarks/source-datocms/gatsby-node.js index 4e53a79c06bb2..75f590e92c7a0 100644 --- a/benchmarks/source-datocms/gatsby-node.js +++ b/benchmarks/source-datocms/gatsby-node.js @@ -1,15 +1,9 @@ const kebabCase = require(`lodash.kebabcase`) -function unstable_shouldOnCreateNode({node}) { - return node.internal.type === `node__article` -} - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode - exports.onCreateNode = ({ actions, node }) => { const { createNodeField } = actions - if (unstable_shouldOnCreateNode({node})) { + if (node.internal.type === `node__article`) { createNodeField({ node, name: `slug`, value: kebabCase(node.title) }) } } diff --git a/benchmarks/source-drupal/gatsby-node.js b/benchmarks/source-drupal/gatsby-node.js index ca3007f4bad09..d161fa76d59a7 100644 --- a/benchmarks/source-drupal/gatsby-node.js +++ b/benchmarks/source-drupal/gatsby-node.js @@ -1,15 +1,9 @@ const kebabCase = require(`lodash.kebabcase`) -function unstable_shouldOnCreateNode({node}) { - return node.internal.type === `node__article` -} - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode - exports.onCreateNode = ({ actions, node }) => { const { createNodeField } = actions - if (unstable_shouldOnCreateNode({node})) { + if (node.internal.type === "node__article") { createNodeField({ node, name: "slug", value: kebabCase(node.title) }) } } diff --git a/benchmarks/source-flotiq/gatsby-node.js b/benchmarks/source-flotiq/gatsby-node.js index 7b29474d0da07..26f4f739e91fe 100644 --- a/benchmarks/source-flotiq/gatsby-node.js +++ b/benchmarks/source-flotiq/gatsby-node.js @@ -1,15 +1,9 @@ const kebabCase = require(`lodash.kebabcase`) -function unstable_shouldOnCreateNode({node}) { - return node.internal.type === `node__article` -} - -exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode - exports.onCreateNode = ({ actions, node }) => { const { createNodeField } = actions - if (unstable_shouldOnCreateNode({node})) { + if (node.internal.type === "node__article") { createNodeField({ node, name: "slug", value: kebabCase(node.title) }) } } diff --git a/packages/gatsby-plugin-mdx/gatsby-node.js b/packages/gatsby-plugin-mdx/gatsby-node.js index 247fbaf343302..e39974ed0a1c9 100644 --- a/packages/gatsby-plugin-mdx/gatsby-node.js +++ b/packages/gatsby-plugin-mdx/gatsby-node.js @@ -15,7 +15,7 @@ const { exports.sourceNodes = require(`./gatsby/source-nodes`) /** - * Check whether the Create Mdx nodes from MDX files. + * Check whether to create Mdx nodes from MDX files. */ exports.unstable_shouldOnCreateNode = unstable_shouldOnCreateNode