-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.ts
174 lines (158 loc) · 9.97 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import path from 'path';
import type { GatsbyNode } from 'gatsby';
interface PageInput {
path: string;
component: string;
context?: Record<string, any>;
}
interface MdxNode {
id: string;
frontmatter: {
slug: string;
};
internal: {
contentFilePath: string;
};
}
// remove duplicate pages generated by Gatsby for keeping subfolder organization, but not affecting SEO
export const onCreatePage: GatsbyNode['onCreatePage'] = ({ page, actions }) => {
const { deletePage } = actions;
if (
page.path.startsWith('/main/') ||
page.path.startsWith('/posts/') ||
page.path.startsWith('/extras/') ||
page.path.startsWith('/freelance-subpages/')
) {
deletePage(page);
}
};
// avoid conflicting order for styles (removes warnings from console)
export const onCreateWebpackConfig: GatsbyNode['onCreateWebpackConfig'] = ({ actions, getConfig }) => {
const config = getConfig();
config.plugins.forEach((plugin: any) => {
if (plugin.constructor.name === "MiniCssExtractPlugin") {
plugin.options.ignoreOrder = true;
}
});
actions.replaceWebpackConfig(config);
};
export const createPages: GatsbyNode['createPages'] = async ({ actions, graphql }) => {
const { createPage } = actions;
const result = await graphql<{ allMdx: { nodes: MdxNode[] } }>(`
{
allMdx {
nodes {
id
frontmatter {
slug
}
internal {
contentFilePath
}
}
}
}
`);
if (result.errors) {
throw new Error(result.errors.join('\n'));
}
const excludedFiles = [
'adventures_template.mdx',
'research_template.mdx',
'thoughts_template.mdx'
];
// process mdx files of posts by checking if the contentFilePath includes 'src/pages/posts', but not excludedFiles
result.data?.allMdx.nodes.forEach((node) => {
if (excludedFiles.some((templateName) => node.internal.contentFilePath.includes(templateName))) {
return;
}
if (node.internal.contentFilePath.includes('src/pages/posts')) {
const PostTemplate = process.env.NODE_ENV === "development"
? path.resolve(`./src/templates/post_development.tsx`)
: path.resolve(`./src/templates/post.tsx`);
const slug = node.frontmatter.slug;
const slugParts = slug.split('/').filter(part => part !== '');
const section = slugParts[0];
const postName = slugParts[1];
const postsFilterRegex = `/${section}/`;
createPage({
path: node.frontmatter.slug,
component: `${PostTemplate}?__contentFilePath=${node.internal.contentFilePath}`,
context: {
id: node.id,
postsFilterRegex,
imagePathRegex: `^posts/${section}/content/${postName}/`,
},
});
}
});
// helper function to create pages with proper TypeScript typing
const createTypedPage = (pageInput: PageInput) => {
createPage(pageInput);
};
createTypedPage({path: "/frog", component: path.resolve(`src/components/NotFound/index.tsx`)});
createTypedPage({path: "/adventures", component: path.resolve(`src/pages/main/adventures.tsx`)});
createTypedPage({path: "/research", component: path.resolve(`src/pages/main/research.tsx`)});
createTypedPage({path: "/thoughts", component: path.resolve(`src/pages/main/thoughts.tsx`)});
createTypedPage({path: "/tags", component: path.resolve(`src/pages/main/tags.tsx`)});
createTypedPage({path: "/handbook", component: path.resolve(`src/pages/main/travel_handbook.tsx`)});
createTypedPage({path: "/publications", component: path.resolve(`src/pages/main/publications.tsx`)});
createTypedPage({path: "/software", component: path.resolve(`src/pages/main/software.tsx`)});
createTypedPage({path: "/music", component: path.resolve(`src/pages/main/music.tsx`)});
createTypedPage({path: "/course", component: path.resolve(`src/pages/main/course.tsx`)});
createTypedPage({path: "/talks", component: path.resolve(`src/pages/main/talks.tsx`)});
createTypedPage({path: "/goals", component: path.resolve(`src/pages/main/goals.tsx`)});
createTypedPage({path: "/exploration", component: path.resolve(`src/pages/main/exploration.tsx`)});
createTypedPage({path: "/freelance", component: path.resolve(`src/pages/main/freelance.tsx`)});
createTypedPage({path: "/freelance/ru", component: path.resolve(`src/pages/main/freelance_ru.tsx`)});
createTypedPage({path: "/freelance/services", component: path.resolve(`src/pages/freelance-subpages/services.mdx`)});
createTypedPage({path: "/freelance/ru/services", component: path.resolve(`src/pages/freelance-subpages/services_ru.mdx`)});
createTypedPage({path: "/freelance/projects/machine_learning", component: path.resolve(`src/pages/freelance-subpages/machine_learning.tsx`)});
createTypedPage({path: "/freelance/ru/projects/machine_learning", component: path.resolve(`src/pages/freelance-subpages/machine_learning_ru.tsx`)});
createTypedPage({path: "/freelance/projects/data_analysis", component: path.resolve(`src/pages/freelance-subpages/data_analysis.tsx`)});
createTypedPage({path: "/freelance/ru/projects/data_analysis", component: path.resolve(`src/pages/freelance-subpages/data_analysis_ru.tsx`)});
createTypedPage({path: "/freelance/projects/data_visualization", component: path.resolve(`src/pages/freelance-subpages/data_visualization.tsx`)});
createTypedPage({path: "/freelance/ru/projects/data_visualization", component: path.resolve(`src/pages/freelance-subpages/data_visualization_ru.tsx`)});
createTypedPage({path: "/freelance/projects/data_collection", component: path.resolve(`src/pages/freelance-subpages/data_collection.tsx`)});
createTypedPage({path: "/freelance/ru/projects/data_collection", component: path.resolve(`src/pages/freelance-subpages/data_collection_ru.tsx`)});
createTypedPage({path: "/freelance/projects/python_apps", component: path.resolve(`src/pages/freelance-subpages/python_apps.tsx`)});
createTypedPage({path: "/freelance/ru/projects/python_apps", component: path.resolve(`src/pages/freelance-subpages/python_apps_ru.tsx`)});
createTypedPage({path: "/freelance/projects/web_development", component: path.resolve(`src/pages/freelance-subpages/web_development.tsx`)});
createTypedPage({path: "/freelance/ru/projects/web_development", component: path.resolve(`src/pages/freelance-subpages/web_development_ru.tsx`)});
createTypedPage({path: "/freelance/projects/research", component: path.resolve(`src/pages/freelance-subpages/research.tsx`)});
createTypedPage({path: "/freelance/ru/projects/research", component: path.resolve(`src/pages/freelance-subpages/research_ru.tsx`)});
createTypedPage({path: "/freelance/projects/technical_writing", component: path.resolve(`src/pages/freelance-subpages/technical_writing.tsx`)});
createTypedPage({path: "/freelance/ru/projects/technical_writing", component: path.resolve(`src/pages/freelance-subpages/technical_writing_ru.tsx`)});
createTypedPage({path: "/freelance/projects/post_production", component: path.resolve(`src/pages/freelance-subpages/post_production.tsx`)});
createTypedPage({path: "/freelance/ru/projects/post_production", component: path.resolve(`src/pages/freelance-subpages/post_production_ru.tsx`)});
createTypedPage({path: "/freelance/projects/misc", component: path.resolve(`src/pages/freelance-subpages/misc.tsx`)});
createTypedPage({path: "/freelance/ru/projects/misc", component: path.resolve(`src/pages/freelance-subpages/misc_ru.tsx`)});
createTypedPage({path: "/cv", component: path.resolve(`src/pages/main/cv.tsx`)});
createTypedPage({path: "/about", component: path.resolve(`src/pages/main/about.tsx`)});
createTypedPage({path: "/gallery", component: path.resolve(`src/pages/main/gallery.tsx`)});
createTypedPage({path: "/stories", component: path.resolve(`src/pages/main/stories.tsx`)});
createTypedPage({path: "/zettelkasten", component: path.resolve(`src/pages/main/zettelkasten.tsx`)});
createTypedPage({path: "/articles", component: path.resolve(`src/pages/main/articles.tsx`)});
createTypedPage({path: "/websites", component: path.resolve(`src/pages/main/websites.tsx`)});
createTypedPage({path: "/videos", component: path.resolve(`src/pages/main/videos.tsx`)});
createTypedPage({path: "/feed", component: path.resolve(`src/pages/main/feed.tsx`)});
createTypedPage({path: "/playlists", component: path.resolve(`src/pages/main/playlists.tsx`)});
createTypedPage({path: "/albums", component: path.resolve(`src/pages/main/albums.tsx`)});
createTypedPage({path: "/films", component: path.resolve(`src/pages/main/films.tsx`)});
createTypedPage({path: "/bookshelf", component: path.resolve(`src/pages/main/bookshelf.tsx`)});
createTypedPage({path: "/hall_of_fame", component: path.resolve(`src/pages/main/hall_of_fame.tsx`)});
createTypedPage({path: "/gear", component: path.resolve(`src/pages/main/gear.tsx`)});
createTypedPage({path: "/calisthenics", component: path.resolve(`src/pages/main/calisthenics.tsx`)});
createTypedPage({path: "/friends", component: path.resolve(`src/pages/main/friends.tsx`)});
createTypedPage({path: "/habits", component: path.resolve(`src/pages/main/habits.tsx`)});
createTypedPage({path: "/faq", component: path.resolve(`src/pages/main/faq.tsx`)});
createTypedPage({path: "/information_for_business_inquiries", component: path.resolve(`src/pages/extras/information_for_business_inquiries.tsx`)});
createTypedPage({path: "/donate", component: path.resolve(`src/pages/extras/donate.tsx`)});
createTypedPage({path: "/contact", component: path.resolve(`src/pages/extras/contact.tsx`)});
createTypedPage({path: "/all", component: path.resolve(`src/pages/extras/all_posts.tsx`)});
createTypedPage({path: "/dev", component: path.resolve(`src/pages/extras/dev.tsx`)});
createTypedPage({path: "/dev/null", component: path.resolve(`src/pages/extras/dev_null.tsx`)});
createTypedPage({path: "/dev/magnitoshakhtinsk", component: path.resolve(`src/pages/extras/dev_magnitoshakhtinsk.tsx`)});
createTypedPage({path: "/null", component: path.resolve(`src/pages/extras/dev_null.tsx`)});
createTypedPage({path: "/avrtt", component: path.resolve(`src/pages/extras/avrtt.tsx`)});
};