@eventcatalog/core 2.0.12 → 2.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @eventcatalog/core
2
2
 
3
+ ## 2.0.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 9d61581: feat(core): added support for base url and slashes
8
+
9
+ ## 2.0.13
10
+
11
+ ### Patch Changes
12
+
13
+ - 1e4c805: feat(core): Adding <SchemaViewer /> component
14
+
3
15
  ## 2.0.12
4
16
 
5
17
  ### Patch Changes
package/astro.config.mjs CHANGED
@@ -9,12 +9,13 @@ import remarkGFM from 'remark-gfm';
9
9
  import pagefind from "astro-pagefind";
10
10
  import { mermaid } from "./src/remark-plugins/mermaid"
11
11
 
12
+
12
13
  import expressiveCode from 'astro-expressive-code';
13
14
  import config from './eventcatalog.config';
14
15
 
15
16
  // https://astro.build/config
16
17
  export default defineConfig({
17
- base: '/',
18
+ base: config.base || '/',
18
19
  server: { port: 3000 },
19
20
 
20
21
  // https://docs.astro.build/en/reference/configuration-reference/#site
@@ -7,6 +7,7 @@ interface Config {
7
7
  organizationName: string;
8
8
  homepageLink: string;
9
9
  editUrl: string;
10
+ base?: string;
10
11
  logo: {
11
12
  alt: string;
12
13
  src: string;
@@ -7,6 +7,7 @@ interface Config {
7
7
  organizationName: string;
8
8
  homepageLink: string;
9
9
  editUrl: string;
10
+ base?: string;
10
11
  logo: {
11
12
  alt: string;
12
13
  src: string;
@@ -8,6 +8,7 @@ export interface Config {
8
8
  organizationName: string;
9
9
  homepageLink: string;
10
10
  editUrl: string;
11
+ base?: string;
11
12
  logo: {
12
13
  alt: string;
13
14
  src: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@eventcatalog/core",
3
3
  "type": "module",
4
- "version": "2.0.12",
4
+ "version": "2.0.14",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -21,7 +21,7 @@
21
21
  "astro": "astro",
22
22
  "scripts:hydrate-content": "node scripts/catalog-to-astro-content-directory.js",
23
23
  "start:catalog": "node scripts/start-catalog-locally.js",
24
- "verify-build:catalog": "rimraf packages/eventcatalog/dist && npm run build:cd",
24
+ "verify-build:catalog": "rimraf dist && npm run build:cd",
25
25
  "changeset": "changeset",
26
26
  "release": "changeset publish",
27
27
  "format": "prettier --config .prettierrc --write \"**/*.{js,jsx,ts,tsx,json}\"",
@@ -36,6 +36,8 @@
36
36
  "@changesets/cli": "^2.27.5",
37
37
  "@headlessui/react": "^2.0.3",
38
38
  "@heroicons/react": "^2.1.3",
39
+ "@stoplight/json-schema-viewer": "^4.7.0",
40
+ "@stoplight/mosaic": "^1.53.2",
39
41
  "@tailwindcss/typography": "^0.5.13",
40
42
  "@tanstack/react-table": "^8.17.3",
41
43
  "@types/dagre": "^0.7.52",
@@ -6,6 +6,7 @@ import { getServices } from '@utils/services/services';
6
6
  import { getTeams } from '@utils/teams';
7
7
  import { getUsers } from '@utils/users';
8
8
  import config, { type CatalogConfig } from '@eventcatalog';
9
+ import { buildUrl } from '@utils/url-builder';
9
10
 
10
11
  const events = await getEvents({ getAllVersions: false });
11
12
  const commands = await getCommands({ getAllVersions: false });
@@ -59,7 +60,7 @@ const sideNav = withHeadings.reduce((acc, item) => {
59
60
  items: item.collection === 'users' ? [] : item.headings,
60
61
  visible: visibleCollections[item.collection],
61
62
  // @ts-ignore
62
- href: item.data.version ? `/docs/${item.collection}/${item.data.id}/${item.data.version}` : `/docs/${item.collection}/${item.data.id}`,
63
+ href: item.data.version ? buildUrl(`/docs/${item.collection}/${item.data.id}/${item.data.version}`) : buildUrl(`/docs/${item.collection}/${item.data.id}`),
63
64
  };
64
65
 
65
66
  group.push(navigationItem);
@@ -2,31 +2,31 @@
2
2
  import catalog from '@eventcatalog';
3
3
  // import Search from 'astro-pagefind/components/Search';
4
4
  import Search from '@components/Search.astro';
5
+ import { buildUrl } from '@utils/url-builder';
5
6
 
6
7
  const currentPath = Astro.url.pathname;
7
8
 
8
9
  const navItems = [
9
10
  {
10
11
  label: 'Docs',
11
- href: '/docs',
12
+ href: buildUrl('/docs'),
12
13
  },
13
14
  {
14
15
  label: 'Visualiser',
15
- href: '/visualiser',
16
+ href: buildUrl('/visualiser'),
16
17
  },
17
18
  {
18
19
  label: 'Discover',
19
- href: '/discover/events',
20
+ href: buildUrl('/discover/events'),
20
21
  }
21
22
  ];
22
23
 
23
24
  ---
24
-
25
25
  <nav class="md:fixed top-0 w-full z-20 bg-white border-b border-gray-200 py-4 font-bold text-xl max-w-[70em]">
26
26
  <div class="flex justify-between items-center">
27
27
  <div class="w-1/3 flex space-x-2 items-center">
28
- <a href="/docs" class="flex space-x-2 items-center">
29
- <img src="/logo.png" class="w-8" />
28
+ <a href={buildUrl('/docs')} class="flex space-x-2 items-center">
29
+ <img src={buildUrl('/logo.png', true)} class="w-8" />
30
30
  <span class="hidden sm:inline-block text-[1em]">{catalog.title}</span>
31
31
  </a>
32
32
  </div>
@@ -25,8 +25,8 @@ export default function Admonition({ children, type = 'info', className = '' }:
25
25
  <div className={`bg-${color}-50 border-l-4 border-${color}-400 my-4 ${className}`}>
26
26
  <div className="flex">
27
27
  <div className="ml-3 py-2 text-sm flex items-center">
28
- <Icon className={`inline-block mr-2 h-5 w-5 text-${color}-400`} aria-hidden="true" />
29
- {children}
28
+ <Icon className={`block mr-2 h-7 w-7 text-${color}-400`} aria-hidden="true" />
29
+ <div>{children}</div>
30
30
  </div>
31
31
  </div>
32
32
  </div>
@@ -9,6 +9,7 @@ import type { CollectionEntry } from 'astro:content';
9
9
  import { navigate } from 'astro:transitions/client';
10
10
  import type { CollectionTypes } from '@types';
11
11
  import DownloadButton from './DownloadButton';
12
+ import { buildUrl } from '@utils/url-builder';
12
13
 
13
14
  interface Props {
14
15
  nodes: any;
@@ -21,10 +22,10 @@ interface Props {
21
22
  }
22
23
 
23
24
  const getDocUrlForCollection = (collectionItem: CollectionEntry<CollectionTypes>) => {
24
- return `/docs/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}`;
25
+ return buildUrl(`/docs/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}`);
25
26
  };
26
27
  const getVisualiserUrlForCollection = (collectionItem: CollectionEntry<CollectionTypes>) => {
27
- return `/visualiser/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}`;
28
+ return buildUrl(`/visualiser/${collectionItem.collection}/${collectionItem.data.id}/${collectionItem.data.version}`);
28
29
  };
29
30
 
30
31
  // const NodeGraphBuilder = ({ title, subtitle, includeBackground = true, includeControls = true }: Props) => {
@@ -0,0 +1,94 @@
1
+ ---
2
+ const { catalog, id } = Astro.props;
3
+ import fs from 'node:fs/promises';
4
+ import { existsSync } from 'fs';
5
+ import path from 'path';
6
+ import SchemaViewerClient from './SchemaViewer'
7
+ import Admonition from '../Admonition';
8
+ let schemas = [];
9
+
10
+ function findSchemaViewers(document: string) {
11
+ // Define regex pattern to match <SchemaViewer ... />
12
+ const pattern = /<SchemaViewer\s+([^>]*)\/>/g;
13
+
14
+ // Find all matches of the pattern
15
+ const matches = [...document.matchAll(pattern)];
16
+
17
+ // Extract the properties of each SchemaViewer
18
+ const schemaViewers = matches.map(match => {
19
+ const propsString = match[1];
20
+ const props = {};
21
+
22
+ // Use regex to extract key-value pairs from propsString
23
+ const propsPattern = /(\w+)=["']([^"']+)["']/g;
24
+ let propMatch;
25
+ while ((propMatch = propsPattern.exec(propsString)) !== null) {
26
+ const key = propMatch[1];
27
+ const value = propMatch[2];
28
+ // @ts-ignore
29
+ props[key] = value;
30
+ }
31
+
32
+ return props;
33
+ });
34
+
35
+ return schemaViewers;
36
+ }
37
+
38
+ try {
39
+ const file = await fs.readFile(catalog.absoluteFilePath, 'utf-8');
40
+ const schemaViewers = findSchemaViewers(file);
41
+
42
+ // Loop around all the possible SchemaViewers in the file.
43
+ const getAllComponents = schemaViewers.map(async (schemaViewerProps: any) => {
44
+
45
+ const schemaPath = path.join(catalog.filePath, schemaViewerProps.file)
46
+ const exists = existsSync(schemaPath);
47
+ let schema;
48
+
49
+ if(exists) {
50
+ // Load the schema for the component
51
+ schema = await fs.readFile(schemaPath, 'utf-8');
52
+ schema = JSON.parse(schema);
53
+ }
54
+
55
+ return {
56
+ id: schemaViewerProps.id || id,
57
+ exists,
58
+ schema,
59
+ schemaPath,
60
+ ...schemaViewerProps
61
+ }
62
+ });
63
+
64
+ schemas = await Promise.all(getAllComponents);
65
+
66
+ } catch (error) {
67
+ console.log('Failed to process schemas')
68
+ console.log(error);
69
+ }
70
+
71
+ ---
72
+ <section class="space-y-4">
73
+ {schemas.length > 0 &&
74
+ schemas.map((schema) => (
75
+ <div>
76
+
77
+ {schema.exists &&
78
+ <SchemaViewerClient {...schema} client:load />
79
+ }
80
+
81
+ {/* User has tried to load the schema, but it was not found on file system */}
82
+ {!schema.exists && (
83
+ <Admonition type="warning">
84
+ <>
85
+ <span class="block font-bold">{`<SchemaViewer/>`} failed to load</span>
86
+ <span class="block">Tried to load schema from {schema.schemaPath}, but no schema can be found</span>
87
+ </>
88
+ </Admonition>
89
+ )}
90
+
91
+ </div>
92
+ ))
93
+ }
94
+ </section>
@@ -0,0 +1,9 @@
1
+ /* Custom styling for the schema viewer */
2
+ .schemaViewer :global(.svg-inline--fa) {
3
+ width: 1.25em;
4
+ height: 1em;
5
+ }
6
+
7
+ .schemaViewer p, span {
8
+ color: rgb(111, 111, 111) !important;
9
+ }
@@ -0,0 +1,62 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ // @ts-ignore
4
+ import { JsonSchemaViewer } from '@stoplight/json-schema-viewer';
5
+ import styles from './SchemaViewer.module.css';
6
+
7
+ import '@stoplight/mosaic/styles.css';
8
+ import { createPortal } from 'react-dom';
9
+
10
+ type Props = {
11
+ id: string;
12
+ file: string;
13
+ renderRootTreeLines?: boolean;
14
+ hideExamples?: boolean;
15
+ defaultExpandedDepth?: number;
16
+ maxHeight?: string;
17
+ schema: any;
18
+ catalog: any;
19
+ title?: string;
20
+ };
21
+
22
+ const SchemaViewer = ({
23
+ id,
24
+ maxHeight = '500',
25
+ renderRootTreeLines = true,
26
+ hideExamples = false,
27
+ defaultExpandedDepth = 3,
28
+ title,
29
+ schema,
30
+ }: Props) => {
31
+ const [elem, setElem] = useState(null);
32
+ useEffect(() => {
33
+ // @ts-ignore
34
+ setElem(document.getElementById(`${id}-SchemaViewer-portal`));
35
+ }, []);
36
+
37
+ if (!elem) return null;
38
+
39
+ return (
40
+ <div>
41
+ {createPortal(
42
+ <section className="not-prose space-y-2 ">
43
+ {title && <h2 className="text-3xl font-bold">{title}</h2>}
44
+ <div className="border border-gray-100 p-2 schemaViewer">
45
+ <JsonSchemaViewer
46
+ schema={schema}
47
+ emptyText="No schema defined"
48
+ maxHeight={parseInt(maxHeight, 10)}
49
+ defaultExpandedDepth={defaultExpandedDepth}
50
+ renderRootTreeLines={renderRootTreeLines}
51
+ hideExamples={hideExamples}
52
+ className={styles.schemaViewer}
53
+ />
54
+ </div>
55
+ </section>,
56
+ elem
57
+ )}
58
+ </div>
59
+ );
60
+ };
61
+
62
+ export default SchemaViewer;
@@ -0,0 +1,5 @@
1
+ const SchemaViewerPortal = (props: any) => {
2
+ return <div id={`${props.id}-SchemaViewer-portal`} />;
3
+ };
4
+
5
+ export default SchemaViewerPortal;
@@ -1,23 +1,25 @@
1
- // Astro components
2
-
3
1
  // React components
4
2
  import Schema from '@components/MDX/Schema';
5
3
  import File from '@components/MDX/File';
6
4
  import Accordion from '@components/MDX/Accordion/Accordion.astro';
7
5
  import AccordionGroup from '@components/MDX/Accordion/AccordionGroup.astro';
8
6
  import Admonition from '@components/MDX/Admonition';
9
- import NodeGraphPortal from '@components/MDX/NodeGraph/NodeGraphPortal';
10
7
  import OpenAPI from '@components/MDX/OpenAPI/OpenAPI';
11
8
 
9
+ // Portals: required for server/client components
10
+ import NodeGraphPortal from '@components/MDX/NodeGraph/NodeGraphPortal';
11
+ import SchemaViewerPortal from '@components/MDX/SchemaViewer/SchemaViewerPortal';
12
+
12
13
  const components = (props: any) => {
13
14
  return {
14
- AccordionGroup,
15
15
  Accordion,
16
- OpenAPI: (mdxProp: any) => <OpenAPI {...mdxProp} {...props} />,
16
+ AccordionGroup,
17
17
  Admonition: (mdxProp: any) => <Admonition {...mdxProp} {...props} />,
18
18
  File: (mdxProp: any) => File({ ...props, ...mdxProp }),
19
- Schema: (mdxProp: any) => Schema({ ...props, ...mdxProp }),
20
19
  NodeGraph: (mdxProp: any) => NodeGraphPortal({ ...props.data, ...mdxProp }),
20
+ SchemaViewer: (mdxProp: any) => SchemaViewerPortal({ ...props.data, ...mdxProp }),
21
+ OpenAPI: (mdxProp: any) => <OpenAPI {...mdxProp} {...props} />,
22
+ Schema: (mdxProp: any) => Schema({ ...props, ...mdxProp }),
21
23
  };
22
24
  };
23
25
 
@@ -30,7 +30,7 @@ if (typeof _image === 'string') {
30
30
  <meta charset="UTF-8" />
31
31
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
32
32
  <meta name="viewport" content="width=device-width" />
33
- <link rel="icon" type="image/svg+xml" href="/favicon.ico" />
33
+ <link rel="icon" type="image/svg+xml" href={`${import.meta.env.BASE_URL}/favicon.ico`} />
34
34
 
35
35
  <SEO
36
36
  title={title}
@@ -3,6 +3,7 @@ import { RectangleGroupIcon } from '@heroicons/react/20/solid';
3
3
  import { createColumnHelper } from '@tanstack/react-table';
4
4
  import type { CollectionEntry } from 'astro:content';
5
5
  import { filterByName, filterCollectionByName } from '../filters/custom-filters';
6
+ import { buildUrl } from '@utils/url-builder';
6
7
 
7
8
  const columnHelper = createColumnHelper<CollectionEntry<'domains'>>();
8
9
 
@@ -16,7 +17,7 @@ export const columns = () => [
16
17
  return (
17
18
  <div className=" group ">
18
19
  <a
19
- href={`/docs/${messageRaw.collection}/${messageRaw.data.id}/${messageRaw.data.version}`}
20
+ href={buildUrl(`/docs/${messageRaw.collection}/${messageRaw.data.id}/${messageRaw.data.version}`)}
20
21
  className={`group-hover:text-${color}-500 flex space-x-1 items-center`}
21
22
  >
22
23
  <div className={`flex items-center border border-gray-300 shadow-sm rounded-md group-hover:border-${color}-400`}>
@@ -74,7 +75,7 @@ export const columns = () => [
74
75
  return (
75
76
  <li key={consumer.data.id} className="py-1 group ">
76
77
  <a
77
- href={`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`}
78
+ href={buildUrl(`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`)}
78
79
  className="group-hover:text-purple-500 flex space-x-1 items-center "
79
80
  >
80
81
  <div className={`flex items-center border border-gray-300 rounded-md`}>
@@ -104,7 +105,7 @@ export const columns = () => [
104
105
  return (
105
106
  <a
106
107
  className="hover:text-purple-500 hover:underline px-4 font-light"
107
- href={`/visualiser/${domain.collection}/${domain.data.id}/${domain.data.version}`}
108
+ href={buildUrl(`/visualiser/${domain.collection}/${domain.data.id}/${domain.data.version}`)}
108
109
  >
109
110
  Visualiser &rarr;
110
111
  </a>
@@ -5,6 +5,7 @@ import type { CollectionMessageTypes } from '@types';
5
5
  import type { CollectionEntry } from 'astro:content';
6
6
  import { useMemo } from 'react';
7
7
  import { filterByName, filterCollectionByName } from '../filters/custom-filters';
8
+ import { buildUrl } from '@utils/url-builder';
8
9
 
9
10
  const columnHelper = createColumnHelper<CollectionEntry<CollectionMessageTypes>>();
10
11
 
@@ -19,7 +20,7 @@ export const columns = () => [
19
20
  return (
20
21
  <div className=" group ">
21
22
  <a
22
- href={`/docs/${messageRaw.collection}/${messageRaw.data.id}/${messageRaw.data.version}`}
23
+ href={buildUrl(`/docs/${messageRaw.collection}/${messageRaw.data.id}/${messageRaw.data.version}`)}
23
24
  className={`group-hover:text-${color}-500 flex space-x-1 items-center`}
24
25
  >
25
26
  <div className={`flex items-center border border-gray-300 shadow-sm rounded-md group-hover:border-${color}-400`}>
@@ -75,7 +76,7 @@ export const columns = () => [
75
76
  return (
76
77
  <li className="py-2 group flex items-center space-x-2" key={producer.data.id}>
77
78
  <a
78
- href={`/docs/${producer.collection}/${producer.data.id}/${producer.data.version}`}
79
+ href={buildUrl(`/docs/${producer.collection}/${producer.data.id}/${producer.data.version}`)}
79
80
  className="group-hover:text-purple-500 flex space-x-1 items-center "
80
81
  >
81
82
  <div className="flex items-center border border-gray-300 shadow-sm rounded-md">
@@ -115,7 +116,7 @@ export const columns = () => [
115
116
  return (
116
117
  <li key={consumer.data.id} className="py-1 group font-light ">
117
118
  <a
118
- href={`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`}
119
+ href={buildUrl(`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`)}
119
120
  className="group-hover:text-purple-500 flex space-x-1 items-center "
120
121
  >
121
122
  <div className="flex items-center border border-gray-300 shadow-sm rounded-md">
@@ -145,7 +146,7 @@ export const columns = () => [
145
146
  return (
146
147
  <a
147
148
  className="hover:text-purple-500 hover:underline px-4 font-light"
148
- href={`/visualiser/${domain.collection}/${domain.data.id}/${domain.data.version}`}
149
+ href={buildUrl(`/visualiser/${domain.collection}/${domain.data.id}/${domain.data.version}`)}
149
150
  >
150
151
  Visualiser &rarr;
151
152
  </a>
@@ -4,6 +4,7 @@ import { createColumnHelper } from '@tanstack/react-table';
4
4
  import type { CollectionEntry } from 'astro:content';
5
5
  import { useMemo } from 'react';
6
6
  import { filterByName, filterCollectionByName } from '../filters/custom-filters';
7
+ import { buildUrl } from '@utils/url-builder';
7
8
 
8
9
  const columnHelper = createColumnHelper<CollectionEntry<'services'>>();
9
10
 
@@ -18,7 +19,7 @@ export const columns = () => [
18
19
  return (
19
20
  <div className="group font-light">
20
21
  <a
21
- href={`/docs/${messageRaw.collection}/${messageRaw.data.id}/${messageRaw.data.version}`}
22
+ href={buildUrl(`/docs/${messageRaw.collection}/${messageRaw.data.id}/${messageRaw.data.version}`)}
22
23
  className={`group-hover:text-${color}-500 flex space-x-1 items-center`}
23
24
  >
24
25
  <div className={`flex items-center border border-gray-300 shadow-sm rounded-md group-hover:border-${color}-400`}>
@@ -76,7 +77,7 @@ export const columns = () => [
76
77
  return (
77
78
  <li key={consumer.data.id} className="py-1 group font-light ">
78
79
  <a
79
- href={`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`}
80
+ href={buildUrl(`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`)}
80
81
  className="group-hover:text-purple-500 flex space-x-1 items-center "
81
82
  >
82
83
  <div className={`flex items-center border border-gray-300 shadow-sm rounded-md`}>
@@ -118,7 +119,7 @@ export const columns = () => [
118
119
  return (
119
120
  <li key={consumer.data.id} className="py-1 group font-light">
120
121
  <a
121
- href={`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`}
122
+ href={buildUrl(`/docs/${consumer.collection}/${consumer.data.id}/${consumer.data.version}`)}
122
123
  className="group-hover:text-purple-500 flex space-x-1 items-center "
123
124
  >
124
125
  <div className={`flex items-center border border-gray-300 shadow-sm rounded-md`}>
@@ -148,7 +149,7 @@ export const columns = () => [
148
149
  return (
149
150
  <a
150
151
  className="hover:text-purple-500 hover:underline px-4 font-light"
151
- href={`/visualiser/${domain.collection}/${domain.data.id}/${domain.data.version}`}
152
+ href={buildUrl(`/visualiser/${domain.collection}/${domain.data.id}/${domain.data.version}`)}
152
153
  >
153
154
  Visualiser &rarr;
154
155
  </a>
@@ -16,7 +16,7 @@ import catalog from '@eventcatalog';
16
16
  <meta charset="UTF-8" />
17
17
  <meta name="description" content="Astro description" />
18
18
  <meta name="viewport" content="width=device-width" />
19
- <link rel="icon" type="image/svg+xml" href="/favicon.ico" />
19
+ <link rel="icon" type="image/svg+xml" href={`${import.meta.env.BASE_URL}/favicon.ico`} />
20
20
  <meta name="generator" content={Astro.generator} />
21
21
  <title>EventCatalog</title>
22
22
  </head>
@@ -8,6 +8,7 @@ import { getCommands } from '@utils/commands';
8
8
  import { getDomains } from '@utils/domains/domains';
9
9
  import { getEvents } from '@utils/events';
10
10
  import { getServices } from '@utils/services/services';
11
+ import { buildUrl } from '@utils/url-builder';
11
12
 
12
13
  const events = await getEvents();
13
14
  const commands = await getCommands();
@@ -20,7 +21,7 @@ const currentPath = Astro.url.pathname;
20
21
  const tabs = [
21
22
  {
22
23
  label: `Events (${events.length})`,
23
- href: '/discover/events',
24
+ href: buildUrl('/discover/events'),
24
25
  isActive: currentPath === '/discover/events',
25
26
  icon: EnvelopeIcon,
26
27
  activeColor: 'orange',
@@ -28,7 +29,7 @@ const tabs = [
28
29
  },
29
30
  {
30
31
  label: `Commands (${commands.length})`,
31
- href: '/discover/commands',
32
+ href: buildUrl('/discover/commands'),
32
33
  isActive: currentPath === '/discover/commands',
33
34
  icon: EnvelopeIcon,
34
35
  activeColor: 'blue',
@@ -36,7 +37,7 @@ const tabs = [
36
37
  },
37
38
  {
38
39
  label: `Services (${services.length})`,
39
- href: '/discover/services',
40
+ href: buildUrl('/discover/services'),
40
41
  isActive: currentPath === '/discover/services',
41
42
  icon: ServerIcon,
42
43
  activeColor: 'pink',
@@ -44,7 +45,7 @@ const tabs = [
44
45
  },
45
46
  {
46
47
  label: `Domains (${domains.length})`,
47
- href: '/discover/domains',
48
+ href: buildUrl('/discover/domains'),
48
49
  isActive: currentPath === '/discover/domains',
49
50
  icon: RectangleGroupIcon,
50
51
  activeColor: 'yellow',
@@ -6,6 +6,7 @@ import { getCommands } from '@utils/commands';
6
6
  import { getDomains } from '@utils/domains/domains';
7
7
  import { getEvents } from '@utils/events';
8
8
  import { getServices } from '@utils/services/services';
9
+ import { buildUrl } from '@utils/url-builder';
9
10
  import type { CollectionEntry } from 'astro:content';
10
11
  import { ViewTransitions } from 'astro:transitions';
11
12
 
@@ -55,7 +56,7 @@ const getColor = (collection: string) => {
55
56
  label: item.data.name,
56
57
  version: item.data.version,
57
58
  color: getColor(item.collection),
58
- href: `/visualiser/${item.collection}/${item.data.id}/${item.data.version}`,
59
+ href: buildUrl(`/visualiser/${item.collection}/${item.data.id}/${item.data.version}`),
59
60
  active: isCurrent
60
61
  }
61
62
  });
@@ -11,7 +11,7 @@ export async function getStaticPaths() {
11
11
  const events = await getEvents();
12
12
  const commands = await getCommands();
13
13
  const services = await getServices();
14
- const domains = await getDomains();
14
+ const domains = await getDomains();
15
15
 
16
16
  const buildPages = (collection: CollectionEntry<CollectionTypes>[]) => {
17
17
  return collection.map((item) => ({
@@ -16,6 +16,7 @@ import { EnvelopeIcon, PencilIcon, RectangleGroupIcon, ServerIcon } from '@heroi
16
16
  import { getDomains } from '@utils/domains/domains';
17
17
  import DomainSideBar from '@components/SideBars/DomainSideBar.astro';
18
18
  import type { CollectionTypes } from '@types';
19
+ import SchemaViewer from '@components/MDX/SchemaViewer/SchemaViewer.astro';
19
20
 
20
21
  export async function getStaticPaths() {
21
22
  const events = await getEvents();
@@ -67,6 +68,7 @@ const badges = [
67
68
  getBadge(),
68
69
  ...contentBadges
69
70
  ];
71
+
70
72
  ---
71
73
 
72
74
  <DocsLayout title={pageTitle} description={props.data.summary}>
@@ -90,13 +92,6 @@ const badges = [
90
92
  )
91
93
  }
92
94
  </div>
93
-
94
- <!-- <div class="hidden md:block opacity-50 md:pr-10">
95
- {props.collection === 'services' && <ServerIcon className="w-20 h-20 text-pink-500" />}
96
- {props.collection === 'events' && <EnvelopeIcon className="w-20 h-20 text-orange-500" />}
97
- {props.collection === 'commands' && <EnvelopeIcon className="w-20 h-20 text-blue-500" />}
98
- {props.collection === 'domains' && <RectangleGroupIcon className="w-20 h-20 text-yellow-500" />}
99
- </div> -->
100
95
  </div>
101
96
 
102
97
  <div>
@@ -131,9 +126,11 @@ const badges = [
131
126
  </div>
132
127
 
133
128
  <div class="prose prose-md py-4 w-full">
134
- <Content components={components(props)} />
129
+ <Content components={components(props)} />
135
130
  </div>
136
131
  <div>
132
+ <!-- @ts-ignore -->
133
+ <SchemaViewer id={props.data.id} catalog={props.catalog} />
137
134
  <NodeGraph id={props.data.id} collection={props.collection} version={props.data.version} mode="simple" href={{ label: 'Open in Visualiser', url: `/visualiser/${props.collection}/${props.data.id}/${props.data.version}`}} />
138
135
  </div>
139
136
  <footer class="py-4 space-y-8 divide-y divide-gray-200/60">
@@ -177,7 +174,16 @@ const badges = [
177
174
 
178
175
  </style>
179
176
 
177
+
178
+ <script define:vars={{ props }}>
179
+ // Fix to pass information to componets that are client side only
180
+ // and require catalog information
181
+ window.eventcatalog = {};
182
+ window.eventcatalog[`${props.collection}-${props.data.id}`] = props.catalog;
183
+ </script>
184
+
180
185
  <script>
186
+
181
187
  /**
182
188
  * @params {HTMLCollectionOf<HTMLElement>} graphs
183
189
  */
@@ -1,7 +1,9 @@
1
1
  import { getCollection } from 'astro:content';
2
2
  import type { CollectionEntry } from 'astro:content';
3
3
  import path from 'path';
4
- import { getVersionForCollectionItem, getVersions } from './collections/util';
4
+ import { getVersionForCollectionItem } from './collections/util';
5
+
6
+ const PROJECT_DIR = process.env.PROJECT_DIR || process.cwd();
5
7
 
6
8
  type Command = CollectionEntry<'commands'> & {
7
9
  catalog: {
@@ -51,6 +53,7 @@ export const getCommands = async ({ getAllVersions = true }: Props = {}): Promis
51
53
  },
52
54
  catalog: {
53
55
  path: path.join(command.collection, command.id.replace('/index.mdx', '')),
56
+ absoluteFilePath: path.join(PROJECT_DIR, command.collection, command.id.replace('/index.mdx', '/index.md')),
54
57
  filePath: path.join(process.cwd(), 'src', 'catalog-files', command.collection, command.id.replace('/index.mdx', '')),
55
58
  publicPath: path.join('/generated', command.collection, command.id.replace('/index.mdx', '')),
56
59
  type: 'command',
@@ -3,6 +3,8 @@ import { getCollection } from 'astro:content';
3
3
  import type { CollectionEntry } from 'astro:content';
4
4
  import path from 'path';
5
5
 
6
+ const PROJECT_DIR = process.env.PROJECT_DIR || process.cwd();
7
+
6
8
  export type Domain = CollectionEntry<'domains'>;
7
9
 
8
10
  interface Props {
@@ -41,6 +43,7 @@ export const getDomains = async ({ getAllVersions = true }: Props = {}): Promise
41
43
  },
42
44
  catalog: {
43
45
  path: path.join(domain.collection, domain.id.replace('/index.mdx', '')),
46
+ absoluteFilePath: path.join(PROJECT_DIR, domain.collection, domain.id.replace('/index.mdx', '/index.md')),
44
47
  filePath: path.join(process.cwd(), 'src', 'catalog-files', domain.collection, domain.id.replace('/index.mdx', '')),
45
48
  publicPath: path.join('/generated', domain.collection, domain.id.replace('/index.mdx', '')),
46
49
  type: 'service',
@@ -1,7 +1,9 @@
1
1
  import { getCollection } from 'astro:content';
2
2
  import type { CollectionEntry } from 'astro:content';
3
3
  import path from 'path';
4
- import { getVersionForCollectionItem, getVersions } from './collections/util';
4
+ import { getVersionForCollectionItem } from './collections/util';
5
+
6
+ const PROJECT_DIR = process.env.PROJECT_DIR || process.cwd();
5
7
 
6
8
  type Event = CollectionEntry<'events'> & {
7
9
  catalog: {
@@ -53,6 +55,7 @@ export const getEvents = async ({ getAllVersions = true }: Props = {}): Promise<
53
55
  },
54
56
  catalog: {
55
57
  path: path.join(event.collection, event.id.replace('/index.mdx', '')),
58
+ absoluteFilePath: path.join(PROJECT_DIR, event.collection, event.id.replace('/index.mdx', '/index.md')),
56
59
  filePath: path.join(process.cwd(), 'src', 'catalog-files', event.collection, event.id.replace('/index.mdx', '')),
57
60
  publicPath: path.join('/generated', event.collection, event.id.replace('/index.mdx', '')),
58
61
  type: 'event',
@@ -2,10 +2,8 @@ import { getVersionForCollectionItem, getVersions } from '@utils/collections/uti
2
2
  import { getCollection } from 'astro:content';
3
3
  import type { CollectionEntry } from 'astro:content';
4
4
  import path from 'path';
5
- // import { getEvents } from './events';
6
- // import { getCommands } from './commands';
7
5
 
8
- // import type { Service as ServiceInterface } from '../types/index'
6
+ const PROJECT_DIR = process.env.PROJECT_DIR || process.cwd();
9
7
 
10
8
  export type Service = CollectionEntry<'services'>;
11
9
 
@@ -79,6 +77,7 @@ export const getServices = async ({ getAllVersions = true }: Props = {}): Promis
79
77
  },
80
78
  catalog: {
81
79
  path: path.join(service.collection, service.id.replace('/index.mdx', '')),
80
+ absoluteFilePath: path.join(PROJECT_DIR, service.collection, service.id.replace('/index.mdx', '/index.md')),
82
81
  filePath: path.join(process.cwd(), 'src', 'catalog-files', service.collection, service.id.replace('/index.mdx', '')),
83
82
  publicPath: path.join('/generated', service.collection, service.id.replace('/index.mdx', '')),
84
83
  type: 'service',
@@ -0,0 +1,26 @@
1
+ import config from '@eventcatalog';
2
+
3
+ const cleanUrl = (url: string) => {
4
+ return url.replace(/\/+/g, '/');
5
+ };
6
+
7
+ // Custom URL builder as Astro does not support this stuff out the box
8
+ export const buildUrl = (url: string, ignoreTrailingSlash = false) => {
9
+ // Should a trailingSlash be added to urls?
10
+ const trailingSlash = config.trailingSlash || false;
11
+
12
+ let newUrl = url;
13
+
14
+ // If the base URL is not the root, we need to append it
15
+ if (import.meta.env.BASE_URL !== '/') {
16
+ newUrl = `${import.meta.env.BASE_URL}${url}`;
17
+ }
18
+
19
+ // Should we add a trailing slash to the url?
20
+ if (trailingSlash && !ignoreTrailingSlash) {
21
+ if (url.endsWith('/')) return newUrl;
22
+ return cleanUrl(`${newUrl}/`);
23
+ }
24
+
25
+ return cleanUrl(newUrl);
26
+ };