Skip to content

Commit b05b329

Browse files
committed
mdx fixup
1 parent a953b41 commit b05b329

File tree

12 files changed

+636
-341
lines changed

12 files changed

+636
-341
lines changed
File renamed without changes.
File renamed without changes.

content/chat/setup.mdx

Lines changed: 0 additions & 262 deletions
This file was deleted.
File renamed without changes.

data/createPages/index.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,6 @@ interface ApiReferenceQueryResult {
7070
};
7171
}
7272

73-
interface MdxEdge {
74-
node: {
75-
id: string;
76-
frontmatter: {
77-
slug: string;
78-
title: string;
79-
};
80-
internal: {
81-
contentFilePath: string;
82-
};
83-
};
84-
}
85-
86-
interface MdxQueryResult {
87-
allMdx: {
88-
edges: MdxEdge[];
89-
};
90-
}
91-
9273
export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions: { createPage, createRedirect } }) => {
9374
/**
9475
* It's not ideal to have:
@@ -124,25 +105,6 @@ export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions:
124105
}
125106
`);
126107

127-
const mdxResult = await graphql<MdxQueryResult>(`
128-
query {
129-
allMdx {
130-
edges {
131-
node {
132-
id
133-
frontmatter {
134-
slug
135-
title
136-
}
137-
internal {
138-
contentFilePath
139-
}
140-
}
141-
}
142-
}
143-
}
144-
`);
145-
146108
/**
147109
* We could log here, the reason we don't right now is that the error should already have been caught and logged.
148110
* Because Gatsby spawns a bunch of async processes during the onCreateNode step, though, and errors don't prevent
@@ -246,30 +208,6 @@ export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions:
246208
return slug;
247209
};
248210

249-
const mdxCreator = async (edge: MdxEdge): Promise<string> => {
250-
const slug = edge.node.frontmatter.slug;
251-
252-
if (!slug) {
253-
return slug;
254-
}
255-
256-
const mdxWrapper = path.resolve('src/components/Layout/MDXWrapper.tsx');
257-
258-
console.log('cat', edge.node.frontmatter);
259-
260-
createPage({
261-
path: slug,
262-
component: `${mdxWrapper}?__contentFilePath=${edge.node.internal.contentFilePath}`,
263-
context: {
264-
slug,
265-
title: edge.node.frontmatter.title,
266-
layout: { sidebar: true, searchBar: true, template: 'base' },
267-
},
268-
});
269-
270-
return slug;
271-
};
272-
273211
createRedirect({
274212
fromPath: '/',
275213
toPath: '/docs',
@@ -293,11 +231,8 @@ export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions:
293231
throw new Error('API reference result is undefined');
294232
}
295233

296-
console.log('lucie', mdxResult.data);
297-
298234
await Promise.all([
299235
...documentResult.data.allFileHtml.edges.map(documentCreator(documentTemplate)),
300236
...apiReferenceResult.data.allFileHtml.edges.map(documentCreator(apiReferenceTemplate)),
301-
...(mdxResult.data?.allMdx.edges.map(mdxCreator) ?? []),
302237
]);
303238
};

data/onCreatePage.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { GatsbyNode } from 'gatsby';
2+
import path from 'path';
23

34
export type LayoutOptions = { sidebar: boolean; searchBar: boolean; template: string };
45

6+
const mdxWrapper = path.resolve('src/components/Layout/MDXWrapper.tsx');
7+
58
const pageLayoutOptions: Record<string, LayoutOptions> = {
69
'/docs': { sidebar: false, searchBar: false, template: 'index' },
710
'/docs/api/control-api': { sidebar: false, searchBar: true, template: 'control-api' },
@@ -13,15 +16,17 @@ const pageLayoutOptions: Record<string, LayoutOptions> = {
1316

1417
export const onCreatePage: GatsbyNode['onCreatePage'] = ({ page, actions }) => {
1518
const { createPage } = actions;
16-
1719
const pathOptions = Object.entries(pageLayoutOptions).find(([path]) => page.path === path);
20+
const isMDX = page.component.endsWith('.mdx');
1821

19-
if (pathOptions) {
20-
page.context = {
21-
...page.context,
22-
layout: pathOptions[1],
23-
};
24-
25-
createPage(page);
22+
if (pathOptions || isMDX) {
23+
createPage({
24+
...page,
25+
context: {
26+
...page.context,
27+
layout: pathOptions ? pathOptions[1] : { sidebar: true, searchBar: true, template: 'base' },
28+
},
29+
component: isMDX ? `${mdxWrapper}?__contentFilePath=${page.component}` : page.component,
30+
});
2631
}
2732
};

0 commit comments

Comments
 (0)