@eventcatalog/core 2.0.13 → 2.0.15

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.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 73a40b4: fix(core): added support for trailingSlash in the EventCatalog types.
8
+
9
+ ## 2.0.14
10
+
11
+ ### Patch Changes
12
+
13
+ - 9d61581: feat(core): added support for base url and slashes
14
+
3
15
  ## 2.0.13
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,8 @@ interface Config {
7
7
  organizationName: string;
8
8
  homepageLink: string;
9
9
  editUrl: string;
10
+ base?: string;
11
+ trailingSlash?: boolean;
10
12
  logo: {
11
13
  alt: string;
12
14
  src: string;
@@ -7,6 +7,8 @@ interface Config {
7
7
  organizationName: string;
8
8
  homepageLink: string;
9
9
  editUrl: string;
10
+ base?: string;
11
+ trailingSlash?: boolean;
10
12
  logo: {
11
13
  alt: string;
12
14
  src: string;
@@ -8,6 +8,8 @@ export interface Config {
8
8
  organizationName: string;
9
9
  homepageLink: string;
10
10
  editUrl: string;
11
+ base?: string;
12
+ trailingSlash?: boolean;
11
13
  logo: {
12
14
  alt: string;
13
15
  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.13",
4
+ "version": "2.0.15",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -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>
@@ -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) => {
@@ -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) => ({
@@ -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
+ };