-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgatsby-node.ts
More file actions
43 lines (38 loc) · 953 Bytes
/
gatsby-node.ts
File metadata and controls
43 lines (38 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { CreatePagesArgs } from "gatsby";
import path from "path";
exports.createPages = async ({
graphql,
actions,
reporter,
}: CreatePagesArgs) => {
const { createPage } = actions;
const BlogPostTemplate = path.resolve("./src/templates/BlogPostTemplate.tsx");
const result = await graphql<Queries.GatsbyNodeCreatePagesQuery>(`
query GatsbyNodeCreatePages {
allMdx {
nodes {
id
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
}
`);
if (result.errors) {
reporter.panicOnBuild(
"There was an error loading the MDX result",
result.errors,
);
}
result.data?.allMdx.nodes.forEach((node) => {
createPage({
path: `/blog/${node.frontmatter?.slug}`,
component: `${BlogPostTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: { id: node.id },
});
});
};