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

Commit 4846ac5

Browse files
author
dpatanin
committed
query example readmes & render on condition
1 parent 17207d6 commit 4846ac5

2 files changed

Lines changed: 38 additions & 11 deletions

File tree

src/components/ScannerExamples.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { Tab, TabList, TabPanel, Tabs } from 'react-tabs';
55
import 'react-tabs/style/react-tabs.css';
66
import Collapsible from './Collapsible';
77

8-
export default function ScannerExamples({ examples: allExamples }) {
8+
export default function ScannerExamples({
9+
examples: allExamples,
10+
descriptions: allDescriptions,
11+
}) {
912
const exampleGroups = mapValues(
1013
groupBy(allExamples, ({ scanTarget }) => scanTarget),
1114
(examples) => {
@@ -29,6 +32,17 @@ export default function ScannerExamples({ examples: allExamples }) {
2932
trigger={targetName}
3033
triggerTagName="h3"
3134
>
35+
{allDescriptions.some(
36+
(x) => x.node.frontmatter.title === targetName
37+
) && (
38+
<div
39+
dangerouslySetInnerHTML={{
40+
__html: allDescriptions.find(
41+
(x) => x.node.frontmatter.title === targetName
42+
).node.html,
43+
}}
44+
></div>
45+
)}
3246
<TabList>
3347
{examples.map(({ fileName }) => (
3448
<Tab key={fileName}>{fileName.split('.')[0]}</Tab>

src/templates/integration.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import React from "react";
2-
import { graphql } from "gatsby";
3-
import Layout from "../components/Layout";
4-
import ScannerExamples from "../components/ScannerExamples.js";
5-
import Sidebar from "../components/Sidebar.js";
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';
67

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

1010
const Integration = (props) => {
@@ -17,18 +17,19 @@ const Integration = (props) => {
1717

1818
const examples = props.data.examples.nodes.map(({ fields }) => fields);
1919
const showExamples = examples.length > 0;
20+
const exampleReadMes = props.data.exampleReadMes.edges;
2021

2122
return (
2223
<Layout bodyClass="integration">
2324
<div className="sidebar-wrapper">
2425
<Sidebar
2526
categories={[
26-
{ categoryName: "Scanners", entries: scanners },
27+
{ categoryName: 'Scanners', entries: scanners },
2728
{
28-
categoryName: "Persistence Providers",
29+
categoryName: 'Persistence Providers',
2930
entries: persistenceProviders,
3031
},
31-
{ categoryName: "Hooks", entries: hooks },
32+
{ categoryName: 'Hooks', entries: hooks },
3233
]}
3334
currentPathname={props.location.pathname}
3435
/>
@@ -39,7 +40,7 @@ const Integration = (props) => {
3940
className="content"
4041
dangerouslySetInnerHTML={{ __html: html }}
4142
/>
42-
{showExamples && <ScannerExamples examples={examples} />}
43+
{showExamples && <ScannerExamples examples={examples} descriptions={exampleReadMes} />}
4344
</div>
4445
</div>
4546
</div>
@@ -141,6 +142,18 @@ export const query = graphql`
141142
}
142143
}
143144
}
145+
exampleReadMes: allMarkdownRemark(
146+
filter: { fileAbsolutePath: { regex: $exampleFilter } }
147+
) {
148+
edges {
149+
node {
150+
frontmatter {
151+
title
152+
}
153+
html
154+
}
155+
}
156+
}
144157
}
145158
`;
146159

0 commit comments

Comments
 (0)