Skip to content
This repository was archived by the owner on Apr 21, 2026. It is now read-only.

Commit 1228a8f

Browse files
authored
Merge pull request #12 from secureCodeBox/doc-integration-examples
Doc integration examples
2 parents 8b12935 + 463323c commit 1228a8f

5 files changed

Lines changed: 78 additions & 90 deletions

File tree

gatsby-node.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ exports.createPages = ({ graphql, actions }) => {
5353
}
5454
}
5555
}
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-
}
6656
persistenceProvider: allMarkdownRemark(
6757
filter: { fileAbsolutePath: { regex: "/integrations/persistence-provider/" } }
6858
) {
@@ -108,15 +98,6 @@ exports.createPages = ({ graphql, actions }) => {
10898
id: node.id
10999
}
110100
});
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-
});
120101
});
121102
result.data.persistenceProvider.edges.forEach(({ node }) => {
122103
const component = path.resolve("src/templates/integration.js");

src/components/ScannerExamples.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from "react"
2+
import { useStaticQuery, graphql } from "gatsby"
3+
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
4+
import 'react-tabs/style/react-tabs.css';
5+
6+
const PREFIX = 23
7+
export default function ScannerExamples(props) {
8+
9+
console.log(props.scanner);
10+
11+
const scanner = props.scanner.substring(PREFIX);
12+
const query = graphql`
13+
query {
14+
examples: allFile(filter: {base: {regex: "/^(findings|scan).yaml/"}, extension: {eq: "yaml"}}) {
15+
edges {
16+
node {
17+
base
18+
relativeDirectory
19+
}
20+
}
21+
nodes {
22+
fields {
23+
content
24+
fileName
25+
scanTarget
26+
}
27+
}
28+
}
29+
}`;
30+
const data = useStaticQuery(query);
31+
const targets = [];
32+
const examples = [];
33+
34+
const length = data.examples.edges.length
35+
let i;
36+
for (i = 0; i < length; i++) {
37+
const edge = data.examples.edges[i];
38+
const node = data.examples.nodes[i];
39+
if (edge.node.relativeDirectory.includes(scanner)) {
40+
const target = data.examples.nodes[i].fields.scanTarget
41+
if(!targets.includes(target))
42+
targets.push(target);
43+
examples.push(node);
44+
}
45+
}
46+
47+
return (
48+
<div className="container-fluid">
49+
<h2 className="title">Examples</h2>
50+
<Tabs>
51+
<TabList>
52+
{targets.map(target => (<Tab key={target}>{target}</Tab>))}
53+
</TabList>
54+
{targets.map(target => (<TabPanel key={target}>
55+
<Tabs>
56+
<TabList>
57+
{/* We are reversing to ensure that the scan.yaml is shown before the findings.yaml */}
58+
{examples.filter(example => example.fields.scanTarget === target).reverse().map((example, index) => (
59+
<Tab key={index}>{example.fields.fileName.split(".")[0]}</Tab>
60+
))}
61+
</TabList>
62+
63+
{/* We are reversing to ensure that the right text ist displayed for the right file */}
64+
{examples.filter(example => example.fields.scanTarget === target).reverse().map((example, index) => (
65+
<TabPanel key={index}>
66+
<pre><code>{example.fields.content}</code></pre>
67+
</TabPanel>
68+
))}
69+
</Tabs>
70+
</TabPanel>))}
71+
</Tabs>
72+
</div>
73+
);
74+
}

src/pages/integrations/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Layout from '../../components/Layout';
55
import IntegrationCard from '../../components/IntegrationCard';
66

77
const Integrations = (props) => {
8-
const scanner = props.data.scanner.edges;
8+
const scanners = props.data.scanner.edges;
99
const hook = props.data.hook.edges;
1010
const persistenceProvider = props.data.persistenceProvider.edges;
1111

@@ -44,7 +44,7 @@ const Integrations = (props) => {
4444
use.
4545
</p>
4646
</div>
47-
{scanner.map((edge, index) => (
47+
{scanners.map((edge, index) => (
4848
<div
4949
key={index}
5050
className="col-12 col-md-6 col-lg-6 col-sm-12 no-highlight"

src/templates/integration.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from "react";
22
import { graphql, Link } from "gatsby";
33
import Layout from "../components/Layout";
4+
import ScannerExamples from "../components/ScannerExamples.js";
45

56
const Integration = props => {
67
const { title } = props.data.markdownRemark.frontmatter;
@@ -47,6 +48,7 @@ const Integration = props => {
4748
className="content"
4849
dangerouslySetInnerHTML={{ __html: html }}
4950
/>
51+
<ScannerExamples scanner={props.path} />
5052
</div>
5153
</div>
5254
</div>

src/templates/scannerExamples.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)