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

Commit a2a8801

Browse files
authored
Merge pull request #21 from secureCodeBox/feature/example-description
query example readmes & render on condition
2 parents 770b31e + 8e867f8 commit a2a8801

2 files changed

Lines changed: 65 additions & 28 deletions

File tree

src/components/ScannerExamples.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
1-
import groupBy from 'lodash/groupBy';
2-
import mapValues from 'lodash/mapValues';
3-
import React from 'react';
4-
import { Tab, TabList, TabPanel, Tabs } from 'react-tabs';
5-
import 'react-tabs/style/react-tabs.css';
6-
import Collapsible from './Collapsible';
7-
8-
export default function ScannerExamples({ examples: allExamples }) {
9-
const exampleGroups = mapValues(
10-
groupBy(allExamples, ({ scanTarget }) => scanTarget),
11-
(examples) => {
12-
/* We are reversing to ensure that the right text ist displayed for the right file */
13-
return examples.reverse();
14-
}
15-
);
1+
import React from "react";
2+
import { Tab, TabList, TabPanel, Tabs } from "react-tabs";
3+
import "react-tabs/style/react-tabs.css";
4+
import Collapsible from "./Collapsible";
165

6+
export default function ScannerExamples({ examples }) {
177
return (
188
<div className="container-fluid">
199
<h2 className="title">Examples</h2>
2010

21-
{Object.entries(exampleGroups).map(([targetName, examples]) => {
11+
{examples.map(({ name, description, scan, findings }) => {
2212
return (
23-
<Tabs key={targetName}>
13+
<Tabs key={name}>
2414
<Collapsible
2515
overflowWhenOpen="visible"
2616
lazyRender={true}
2717
transitionTime={150}
2818
transitionCloseTime={50}
29-
trigger={targetName}
19+
trigger={name}
3020
triggerTagName="h3"
3121
>
22+
{description && (
23+
<div
24+
dangerouslySetInnerHTML={{
25+
__html: description,
26+
}}
27+
></div>
28+
)}
3229
<TabList>
33-
{examples.map(({ fileName }) => (
34-
<Tab key={fileName}>{fileName.split('.')[0]}</Tab>
35-
))}
30+
{scan && <Tab key={"scan"}>Scan</Tab>}
31+
{findings && <Tab key={"findings"}>Findings</Tab>}
3632
</TabList>
37-
38-
{examples.map(({ fileName, content }) => (
39-
<TabPanel key={fileName}>
33+
{scan && (
34+
<TabPanel key={"scan"}>
35+
<deckgo-highlight-code theme="cobalt">
36+
<code slot="code">{scan}</code>
37+
</deckgo-highlight-code>
38+
</TabPanel>
39+
)}
40+
{findings && (
41+
<TabPanel key={"findings"}>
4042
<deckgo-highlight-code theme="cobalt">
41-
<code slot="code">{content}</code>
43+
<code slot="code">{findings}</code>
4244
</deckgo-highlight-code>
4345
</TabPanel>
44-
))}
46+
)}
4547
</Collapsible>
4648
</Tabs>
4749
);

src/templates/integration.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import React from "react";
22
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+
37
import Layout from "../components/Layout";
48
import ScannerExamples from "../components/ScannerExamples.js";
59
import Sidebar from "../components/Sidebar.js";
610

7-
import { defineCustomElements as deckDeckGoHighlightElement } from "@deckdeckgo/highlight-code/dist/loader";
811
deckDeckGoHighlightElement();
912

1013
const Integration = (props) => {
@@ -15,7 +18,27 @@ 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);
21+
const examplesRaw = props.data.examples.nodes.map(({ fields }) => fields);
22+
const exampleReadMes = props.data.exampleReadMes.edges;
23+
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+
);
1942
const showExamples = examples.length > 0;
2043

2144
return (
@@ -141,6 +164,18 @@ export const query = graphql`
141164
}
142165
}
143166
}
167+
exampleReadMes: allMarkdownRemark(
168+
filter: { fileAbsolutePath: { regex: $exampleFilter } }
169+
) {
170+
edges {
171+
node {
172+
frontmatter {
173+
title
174+
}
175+
html
176+
}
177+
}
178+
}
144179
}
145180
`;
146181

0 commit comments

Comments
 (0)