Skip to content

Commit

Permalink
Drop changes in /benchmarks, fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdz committed Oct 20, 2020
1 parent b759483 commit b7cbef9
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 162 deletions.
31 changes: 13 additions & 18 deletions benchmarks/gabe-csv-markdown/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 9 additions & 14 deletions benchmarks/markdown_id/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 9 additions & 14 deletions benchmarks/markdown_slug/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
32 changes: 14 additions & 18 deletions benchmarks/md/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
18 changes: 8 additions & 10 deletions benchmarks/mdx/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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 }) => {
Expand Down
100 changes: 44 additions & 56 deletions benchmarks/source-agilitycms/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
14 changes: 4 additions & 10 deletions benchmarks/source-cosmicjs/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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) })
}
}
Expand All @@ -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,
},
}
})
})
}
}
8 changes: 1 addition & 7 deletions benchmarks/source-datocms/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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) })
}
}
Expand Down
8 changes: 1 addition & 7 deletions benchmarks/source-drupal/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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) })
}
}
Expand Down
8 changes: 1 addition & 7 deletions benchmarks/source-flotiq/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -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) })
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-mdx/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b7cbef9

Please sign in to comment.