-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathgatsby-node.ts
50 lines (42 loc) · 1.39 KB
/
gatsby-node.ts
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
44
45
46
47
48
49
50
import path from "path";
import { type GatsbyNode } from "gatsby";
const createPages: GatsbyNode["createPages"] = async ({ graphql, actions }) => {
const { createPage } = actions;
const { data } = await graphql<{ allMdx: any }>(`
query {
allMdx {
nodes {
frontmatter {
templateKey
path
}
}
}
}
`);
if (!data) return;
const pathArr = data.allMdx.nodes.filter(({ frontmatter }: { frontmatter: any }) => {
return frontmatter?.path?.match("code-together/course/");
});
const onlyPathArr: string[] = pathArr.map(({ frontmatter }: { frontmatter: any }) => {
return frontmatter.path;
});
const slugList: string[] = [...new Set(onlyPathArr)];
const codeTogetherTemplate = path.resolve("src/template/codeTogetherTemplate.tsx");
slugList.forEach((slug: string) => {
const locationArr = slug.split("/");
const courseName = locationArr[locationArr.length - 1];
createPage({
path: `/${slug}`,
component: codeTogetherTemplate,
context: {
masthead: `codeTogether_${courseName}_masthead`,
registration: `codeTogether_${courseName}_registrations`,
deatilCurriculum: `codeTogether_${courseName}_part*`,
timetable: `codeTogether_${courseName}_plan`,
graduateReview: `codeTogether_${courseName}_reviews`,
},
});
});
};
export { createPages };