-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.ts
73 lines (61 loc) · 1.5 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
import path from 'path';
import {GatsbyNode} from 'gatsby';
const supportedLangs = ['en', 'ar'];
const defaultLang = 'en';
const createPages: GatsbyNode['createPages'] = ({actions}) => {
const {createPage, createRedirect} = actions;
const indexTemplate = path.resolve('./src/templates/index.tsx');
const projectsTemplate = path.resolve('./src/templates/projects.tsx');
const coursesTemplate = path.resolve('./src/templates/courses.tsx');
const errorTemplate = path.resolve('./src/templates/404.tsx');
for (const lang of supportedLangs) {
createPage({
path: `/${lang}/`,
component: indexTemplate,
context: {lang}
});
createPage({
path: `/${lang}/projects/`,
component: projectsTemplate,
context: {lang}
});
createPage({
path: `/${lang}/404.html`,
component: errorTemplate,
context: {lang}
});
if (lang === defaultLang) {
createPage({
path: '/index.html',
component: indexTemplate,
context: {lang}
});
createPage({
path: `/${lang}/courses/`,
component: coursesTemplate,
context: {}
});
createPage({
path: '/404.html',
component: errorTemplate,
context: {lang, multiLangs: true}
});
}
}
createRedirect({
fromPath: '/',
toPath: `/${defaultLang}/`,
redirectInBrowser: true
});
createRedirect({
fromPath: '/index.html',
toPath: `/${defaultLang}/`,
redirectInBrowser: true
});
};
export {createPages};