Skip to content

Commit f774314

Browse files
authored
chore(gabe): add unstable_shouldOnCreateNode handlers to relevant gabe benchmarks (#27568)
1 parent c0668d4 commit f774314

File tree

2 files changed

+45
-43
lines changed

2 files changed

+45
-43
lines changed

benchmarks/gabe-csv-markdown/gatsby-node.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,22 @@ exports.createPages = async ({ graphql, actions }) => {
4242
})
4343
}
4444

45+
exports.unstable_shouldOnCreateNode = ({ node }) =>
46+
node.internal.type === `GendataCsv`
47+
4548
// Not sure if there is a better way than to create a proxy node for markdown to pick up
4649
// I certainly can't get remark to to pick up csv nodes :(
4750
exports.onCreateNode = ({ node, actions }) => {
4851
const { createNode } = actions
4952

50-
if (node.internal.type === `GendataCsv`) {
51-
createNode({
52-
id: `${node.id}-MarkdownProxy`,
53-
parent: node.id,
54-
internal: {
55-
type: `MarkdownProxy`,
56-
mediaType: "text/markdown",
57-
content: node.articleContent,
58-
contentDigest: node.articleContent,
59-
},
60-
})
61-
}
53+
createNode({
54+
id: `${node.id}-MarkdownProxy`,
55+
parent: node.id,
56+
internal: {
57+
type: `MarkdownProxy`,
58+
mediaType: "text/markdown",
59+
content: node.articleContent,
60+
contentDigest: node.articleContent,
61+
},
62+
})
6263
}

benchmarks/gabe-fs-text/gatsby-node.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,40 +40,41 @@ exports.createPages = async ({ graphql, actions }) => {
4040
})
4141
}
4242

43-
exports.onCreateNode = ({ node, actions , createNodeId}) => {
44-
if (node.internal.type === "File") {
45-
// Do minimal processing to get some key pieces. This could be gatsby-transformer-text or -html :p
43+
exports.unstable_shouldOnCreateNode = ({ node }) =>
44+
node.internal.type === "File"
4645

47-
const html = fs.readFileSync(node.absolutePath, "utf8")
46+
exports.onCreateNode = ({ node, actions, createNodeId }) => {
47+
// Do minimal processing to get some key pieces. This could be gatsby-transformer-text or -html :p
4848

49-
const base = path.basename(node.absolutePath)
50-
const slug = base.slice(11, -5) // remove date prefix and `..txt` tail
51-
const date = base.slice(0, 10)
49+
const html = fs.readFileSync(node.absolutePath, "utf8")
5250

53-
const offset1 = html.indexOf("<h1>")
54-
const title = html.slice(
55-
offset1 + "<h1>".length,
56-
html.indexOf("</h1>", offset1)
57-
)
51+
const base = path.basename(node.absolutePath)
52+
const slug = base.slice(11, -5) // remove date prefix and `..txt` tail
53+
const date = base.slice(0, 10)
5854

59-
const offset2 = html.indexOf("<blockquote>", offset1)
60-
const description = html.slice(
61-
offset2 + "<blockquote>".length,
62-
html.indexOf("</blockquote>", offset2)
63-
)
55+
const offset1 = html.indexOf("<h1>")
56+
const title = html.slice(
57+
offset1 + "<h1>".length,
58+
html.indexOf("</h1>", offset1)
59+
)
6460

65-
actions.createNode({
66-
id: createNodeId(slug),
67-
slug,
68-
date,
69-
title,
70-
description,
71-
html,
72-
internal: {
73-
type: "Texto",
74-
contentDigest: html,
75-
},
76-
parent: node.id, // Required otherwise the node is not cached and a warm build screws up. TODO: is touchNode faster?
77-
})
78-
}
61+
const offset2 = html.indexOf("<blockquote>", offset1)
62+
const description = html.slice(
63+
offset2 + "<blockquote>".length,
64+
html.indexOf("</blockquote>", offset2)
65+
)
66+
67+
actions.createNode({
68+
id: createNodeId(slug),
69+
slug,
70+
date,
71+
title,
72+
description,
73+
html,
74+
internal: {
75+
type: "Texto",
76+
contentDigest: html,
77+
},
78+
parent: node.id, // Required otherwise the node is not cached and a warm build screws up. TODO: is touchNode faster?
79+
})
7980
}

0 commit comments

Comments
 (0)