Skip to content

Commit

Permalink
fix/schema-styles (#963)
Browse files Browse the repository at this point in the history
* fix: use Code component into Schema

It uses Code component from astro-expressive-code to load the needed
styles. Code component should be used with astro components or .mdx

Fix #932

* Create weak-poems-walk.md

---------

Co-authored-by: David Boyne <boyneyy123@gmail.com>
  • Loading branch information
carlosallexandre and boyney123 authored Nov 18, 2024
1 parent 8f8d9ec commit b893559
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .changeset/weak-poems-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/core": patch
---

fix(core): fixed issue with styling of schema files
32 changes: 32 additions & 0 deletions src/components/MDX/Schema.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
import fs from 'fs';
import path from 'path';
import { Code } from 'astro-expressive-code/components';
interface Props {
file?: string;
catalog: {
filePath: string;
};
title?: string;
}
const { file = 'schema.json', catalog, title } = Astro.props;
let code: string | null = null;
const exists = fs.existsSync(path.join(catalog.filePath, file));
if (exists) {
code = fs.readFileSync(path.join(catalog.filePath, file), 'utf-8');
}
---

{
code ? (
<div class="not-prose max-w-4xl overflow-x-auto">
<Code code={code} title={title || file} lang="json" />
</div>
) : (
<div class="italic">Tried to load schema from {path.join(catalog.filePath, file)}, but no schema can be found</div>
)
}
45 changes: 0 additions & 45 deletions src/components/MDX/Schema.tsx

This file was deleted.

5 changes: 3 additions & 2 deletions src/components/MDX/components.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// React components
import Schema from '@components/MDX/Schema';
import Schema from '@components/MDX/Schema.astro';
import File from '@components/MDX/File';
import Accordion from '@components/MDX/Accordion/Accordion.astro';
import AccordionGroup from '@components/MDX/Accordion/AccordionGroup.astro';
Expand All @@ -16,6 +16,7 @@ import ChannelInformation from '@components/MDX/ChannelInformation/ChannelInform
// Portals: required for server/client components
import NodeGraphPortal from '@components/MDX/NodeGraph/NodeGraphPortal';
import SchemaViewerPortal from '@components/MDX/SchemaViewer/SchemaViewerPortal';
import { jsx } from 'astro/jsx-runtime';

const components = (props: any) => {
return {
Expand All @@ -33,7 +34,7 @@ const components = (props: any) => {
NodeGraph: (mdxProp: any) => NodeGraphPortal({ ...props.data, ...mdxProp }),
ChannelInformation: (mdxProp: any) => ChannelInformation({ ...props.data, ...mdxProp }),
SchemaViewer: (mdxProp: any) => SchemaViewerPortal({ ...props.data, ...mdxProp }),
Schema: (mdxProp: any) => Schema({ ...props, ...mdxProp }),
Schema: (mdxProp: any) => jsx(Schema, { ...props, ...mdxProp }),
};
};

Expand Down

0 comments on commit b893559

Please sign in to comment.