11const path = require ( "path" ) ;
2+ const fs = require ( "fs" ) ;
23
34// Create pages from markdown files
45exports . createPages = ( { graphql, actions } ) => {
@@ -52,6 +53,16 @@ exports.createPages = ({ graphql, actions }) => {
5253 }
5354 }
5455 }
56+ scannerExamples: allFile(filter: {absolutePath: {regex: "/scanners/(.*)/examples/"}, extension: {eq: "yaml"}}) {
57+ edges {
58+ node {
59+ id
60+ name
61+ extension
62+ dir
63+ }
64+ }
65+ }
5566 persistenceProvider: allMarkdownRemark(
5667 filter: { fileAbsolutePath: { regex: "/integrations/persistence-provider/" } }
5768 ) {
@@ -97,6 +108,15 @@ exports.createPages = ({ graphql, actions }) => {
97108 id : node . id
98109 }
99110 } ) ;
111+
112+ const examplesComponent = path . resolve ( "src/templates/scannerExamples.js" ) ;
113+ createPage ( {
114+ path : `integrations/${ node . frontmatter . path } /examples` ,
115+ component : examplesComponent ,
116+ context : {
117+ basePath : `/${ node . frontmatter . path } /examples/`
118+ }
119+ } ) ;
100120 } ) ;
101121 result . data . persistenceProvider . edges . forEach ( ( { node } ) => {
102122 const component = path . resolve ( "src/templates/integration.js" ) ;
@@ -113,3 +133,15 @@ exports.createPages = ({ graphql, actions }) => {
113133 ) ;
114134 } ) ;
115135} ;
136+
137+ exports . onCreateNode = ( { node, actions } ) => {
138+ const { createNodeField } = actions ;
139+
140+ if ( node . internal . type === `File` && ( node . base === `scan.yaml` || node . base === `findings.yaml` ) ) {
141+ fs . readFile ( node . absolutePath , undefined , ( _err , buf ) => {
142+ createNodeField ( { node, name : `content` , value : buf . toString ( ) } ) ;
143+ } ) ;
144+ createNodeField ( { node, name : `fileName` , value : node . base } ) ;
145+ createNodeField ( { node, name : `scanTarget` , value : node . relativeDirectory . split ( '/examples/' ) [ 1 ] } ) ;
146+ }
147+ }
0 commit comments