@@ -40,40 +40,41 @@ exports.createPages = async ({ graphql, actions }) => {
40
40
} )
41
41
}
42
42
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"
46
45
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
48
48
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" )
52
50
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 )
58
54
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
+ )
64
60
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
+ } )
79
80
}
0 commit comments