Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add rendering of case study asyncapi document #2770

Merged
merged 12 commits into from
Jul 24, 2024
Merged
12 changes: 12 additions & 0 deletions components/helpers/read-yaml-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'fs/promises';

export const readYamlFile = async (fileName) => {
try {
const data = await fs.readFile(`./public/${fileName}`, 'utf-8');
const yamlString = `\`\`\`yaml\n${data}\`\`\``;

return yamlString;
} catch (error) {
throw new Error(`Error: something went wrong while reading ${fileName} file: ${error.message}`);
}
};
12 changes: 12 additions & 0 deletions components/helpers/read-yaml-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import fs from 'fs/promises';

export const readYamlFile = async (fileName: string) => {
try {
const data = await fs.readFile(`./public/${fileName}`, 'utf-8');
const yamlString = `\`\`\`yaml\n${data}\`\`\``;

return yamlString;
} catch (error: any) {
throw new Error(`Error: something went wrong while reading ${fileName} file: ${error.message}`);
}
};
6 changes: 6 additions & 0 deletions pages/casestudies/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Heading from '../../components/typography/Heading';
import Paragraph from '../../components/typography/Paragraph';
import CaseStudiesList from '../../config/case-studies.json';
import { generateCaseStudyContent } from '../../utils/staticHelpers';
import { readYamlFile } from '@/components/helpers/read-yaml-file';

interface IndexProps {
casestudy: ICaseStudy;
Expand All @@ -34,6 +35,7 @@ interface IndexProps {
asyncapiBindings: MDXRemoteSerializeResult;
asyncapiTools: MDXRemoteSerializeResult;
additionalResources: MDXRemoteSerializeResult;
fullExample: MDXRemoteSerializeResult;
}

const renderContent = (
Expand Down Expand Up @@ -96,6 +98,7 @@ const renderContent = (
*/
export async function getStaticProps({ params }: { params: { id: string } }) {
const data = CaseStudiesList.filter((p: { id: string }) => p.id === params.id);
const asyncApiDoc = await readYamlFile(data[0].asyncapi.fullExample);

return {
props: {
Expand All @@ -116,6 +119,7 @@ export async function getStaticProps({ params }: { params: { id: string } }) {
asyncapiDocumentation: await serialize(data[0].asyncapi.documentation),
asyncapiBindings: await serialize(data[0].asyncapi.bindings),
asyncapiTools: await serialize(data[0].asyncapi.tools),
fullExample: await serialize(asyncApiDoc),
additionalResources: await serialize(data[0].additionalResources)
}
};
Expand Down Expand Up @@ -153,6 +157,7 @@ const Index: React.FC<IndexProps> = ({
asyncapiDocumentation,
asyncapiBindings,
asyncapiTools,
fullExample,
additionalResources
}) => {
const image = '/img/social/website-card.png';
Expand All @@ -177,6 +182,7 @@ const Index: React.FC<IndexProps> = ({
asyncapiBindings,
asyncapiTools,
additionalResources,
fullExample,
casestudy
});

Expand Down
5 changes: 5 additions & 0 deletions utils/staticHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const generateCaseStudyContent = (data: any) => {
asyncapiBindings,
asyncapiTools,
additionalResources,
fullExample,
casestudy
} = data;
const { languages } = casestudy.technical;
Expand Down Expand Up @@ -166,6 +167,10 @@ export const generateCaseStudyContent = (data: any) => {
]
}
]
},
{
title: "Production-use AsyncAPI document",
content: fullExample,
}
];
};
Loading