1- import { defineCustomElements as deckDeckGoHighlightElement } from '@deckdeckgo/highlight-code/dist/loader' ;
2- import { graphql } from 'gatsby' ;
3- import React from 'react' ;
4- import Layout from '../components/Layout' ;
5- import ScannerExamples from '../components/ScannerExamples.js' ;
6- import Sidebar from '../components/Sidebar.js' ;
1+ import React from "react" ;
2+ import { graphql } from "gatsby" ;
3+ import { defineCustomElements as deckDeckGoHighlightElement } from "@deckdeckgo/highlight-code/dist/loader" ;
4+ import groupBy from "lodash/groupBy" ;
5+ import map from "lodash/map" ;
6+
7+ import Layout from "../components/Layout" ;
8+ import ScannerExamples from "../components/ScannerExamples.js" ;
9+ import Sidebar from "../components/Sidebar.js" ;
710
811deckDeckGoHighlightElement ( ) ;
912
@@ -15,21 +18,40 @@ const Integration = (props) => {
1518 const persistenceProviders = props . data . persistenceProvider . edges ;
1619 const hooks = props . data . hook . edges ;
1720
18- const examples = props . data . examples . nodes . map ( ( { fields } ) => fields ) ;
19- const showExamples = examples . length > 0 ;
21+ const examplesRaw = props . data . examples . nodes . map ( ( { fields } ) => fields ) ;
2022 const exampleReadMes = props . data . exampleReadMes . edges ;
2123
24+ // Transforms the examples and readme into one big array with he following structure:
25+ // [{ name: "example.com", description: "<html>description", scan: "yaml...", findings: "yaml..."}]
26+ const examples = map (
27+ groupBy ( examplesRaw , ( { scanTarget } ) => scanTarget ) ,
28+ ( examples , scanTarget ) => {
29+ console . log ( { examples, scanTarget } ) ;
30+ return {
31+ name : scanTarget ,
32+ scan : examples . find ( ( { fileName } ) => fileName === "scan.yaml" )
33+ ?. content ,
34+ findings : examples . find ( ( { fileName } ) => fileName === "findings.yaml" )
35+ ?. content ,
36+ description : exampleReadMes . find (
37+ ( x ) => x . node . frontmatter . title === scanTarget
38+ ) ?. node . html ,
39+ } ;
40+ }
41+ ) ;
42+ const showExamples = examples . length > 0 ;
43+
2244 return (
2345 < Layout bodyClass = "integration" >
2446 < div className = "sidebar-wrapper" >
2547 < Sidebar
2648 categories = { [
27- { categoryName : ' Scanners' , entries : scanners } ,
49+ { categoryName : " Scanners" , entries : scanners } ,
2850 {
29- categoryName : ' Persistence Providers' ,
51+ categoryName : " Persistence Providers" ,
3052 entries : persistenceProviders ,
3153 } ,
32- { categoryName : ' Hooks' , entries : hooks } ,
54+ { categoryName : " Hooks" , entries : hooks } ,
3355 ] }
3456 currentPathname = { props . location . pathname }
3557 />
@@ -40,7 +62,7 @@ const Integration = (props) => {
4062 className = "content"
4163 dangerouslySetInnerHTML = { { __html : html } }
4264 />
43- { showExamples && < ScannerExamples examples = { examples } descriptions = { exampleReadMes } /> }
65+ { showExamples && < ScannerExamples examples = { examples } /> }
4466 </ div >
4567 </ div >
4668 </ div >
0 commit comments