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

Commit bd3ac01

Browse files
committed
Extract all logic and gatsby details into integration template
1 parent 4846ac5 commit bd3ac01

2 files changed

Lines changed: 57 additions & 47 deletions

File tree

src/components/ScannerExamples.js

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +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({
9-
examples: allExamples,
10-
descriptions: allDescriptions,
11-
}) {
12-
const exampleGroups = mapValues(
13-
groupBy(allExamples, ({ scanTarget }) => scanTarget),
14-
(examples) => {
15-
/* We are reversing to ensure that the right text ist displayed for the right file */
16-
return examples.reverse();
17-
}
18-
);
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";
195

6+
export default function ScannerExamples({ examples, descriptions = [] }) {
207
return (
218
<div className="container-fluid">
229
<h2 className="title">Examples</h2>
2310

24-
{Object.entries(exampleGroups).map(([targetName, examples]) => {
11+
{examples.map(({ name, description, scan, findings }) => {
2512
return (
26-
<Tabs key={targetName}>
13+
<Tabs key={name}>
2714
<Collapsible
2815
overflowWhenOpen="visible"
2916
lazyRender={true}
3017
transitionTime={150}
3118
transitionCloseTime={50}
32-
trigger={targetName}
19+
trigger={name}
3320
triggerTagName="h3"
3421
>
35-
{allDescriptions.some(
36-
(x) => x.node.frontmatter.title === targetName
37-
) && (
22+
{description && (
3823
<div
3924
dangerouslySetInnerHTML={{
40-
__html: allDescriptions.find(
41-
(x) => x.node.frontmatter.title === targetName
42-
).node.html,
25+
__html: description,
4326
}}
4427
></div>
4528
)}
4629
<TabList>
47-
{examples.map(({ fileName }) => (
48-
<Tab key={fileName}>{fileName.split('.')[0]}</Tab>
49-
))}
30+
{scan && <Tab key={"scan"}>Scan</Tab>}
31+
{findings && <Tab key={"findings"}>Findings</Tab>}
5032
</TabList>
51-
52-
{examples.map(({ fileName, content }) => (
53-
<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"}>
5442
<deckgo-highlight-code theme="cobalt">
55-
<code slot="code">{content}</code>
43+
<code slot="code">{findings}</code>
5644
</deckgo-highlight-code>
5745
</TabPanel>
58-
))}
46+
)}
5947
</Collapsible>
6048
</Tabs>
6149
);

src/templates/integration.js

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
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

811
deckDeckGoHighlightElement();
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

Comments
 (0)