Skip to content

Commit b8730a9

Browse files
authored
fix(core): mdx pages are added to teams and users (event-catalog#1901)
* fix(core): mdx pages are added to teams and users * Create sharp-files-occur.md
1 parent 35a7fae commit b8730a9

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

.changeset/sharp-files-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@eventcatalog/core": patch
3+
---
4+
5+
fix(core): mdx pages are added to teams and users
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file exposes the markdown for EventCatalog in the Url
2+
// For example http://localhost:3000/docs/teams/full-stack loads the Page and http://localhost:3000/docs/teams/full-stack.mdx loads the markdown
3+
// This is used for the LLMs to load the markdown for the given item (llms.txt);
4+
5+
import type { APIRoute } from 'astro';
6+
import { getCollection } from 'astro:content';
7+
import config from '@config';
8+
import fs from 'fs';
9+
10+
const teams = await getCollection('teams');
11+
12+
export async function getStaticPaths() {
13+
// Just return empty array if LLMs are not enabled
14+
if (!config.llmsTxt?.enabled) {
15+
return [];
16+
}
17+
18+
return teams.map((team) => ({
19+
params: { type: 'teams', id: team.data.id },
20+
props: { content: team },
21+
}));
22+
}
23+
24+
export const GET: APIRoute = async ({ params, props }) => {
25+
// Just return empty array if LLMs are not enabled
26+
if (!config.llmsTxt?.enabled) {
27+
return new Response('llms.txt is not enabled for this Catalog.', { status: 404 });
28+
}
29+
30+
if (props?.content?.filePath) {
31+
const file = fs.readFileSync(props.content.filePath, 'utf8');
32+
return new Response(file, { status: 200 });
33+
}
34+
35+
return new Response('Not found', { status: 404 });
36+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file exposes the markdown for EventCatalog in the Url
2+
// For example http://localhost:3000/docs/users/dboyne loads the Page and http://localhost:3000/docs/users/dboyne.mdx loads the markdown
3+
// This is used for the LLMs to load the markdown for the given item (llms.txt);
4+
5+
import type { APIRoute } from 'astro';
6+
import { getCollection } from 'astro:content';
7+
import config from '@config';
8+
import fs from 'fs';
9+
10+
const users = await getCollection('users');
11+
12+
export async function getStaticPaths() {
13+
// Just return empty array if LLMs are not enabled
14+
if (!config.llmsTxt?.enabled) {
15+
return [];
16+
}
17+
18+
return users.map((user) => ({
19+
params: { type: 'users', id: user.data.id },
20+
props: { content: user },
21+
}));
22+
}
23+
24+
export const GET: APIRoute = async ({ params, props }) => {
25+
// Just return empty array if LLMs are not enabled
26+
if (!config.llmsTxt?.enabled) {
27+
return new Response('llms.txt is not enabled for this Catalog.', { status: 404 });
28+
}
29+
30+
if (props?.content?.filePath) {
31+
const file = fs.readFileSync(props.content?.filePath, 'utf8');
32+
return new Response(file, { status: 200 });
33+
}
34+
35+
return new Response('Not found', { status: 404 });
36+
};

0 commit comments

Comments
 (0)