-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
103 lines (92 loc) · 2.64 KB
/
gatsby-node.js
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
const path = require('path');
const createBlogPages = require('./gatsby/node/createBlogPages');
const createTimeToReadNodeField = require('./gatsby/node/createTimeToReadNodeField');
const createDeckNode = require('./gatsby/node/createDeckNode');
const createSlidesPages = require('./gatsby/node/createSlidesPages');
const createTagPages = require('./gatsby/node/createTagPages');
const moveSubsitePage = require('./gatsby/node/moveSubsitePage');
const { SUBSITE } = require('./config/util/subsite');
const mdxResolverPassthrough =
(fieldName) => async (source, args, context, info) => {
const type = info.schema.getType(`Mdx`);
const mdxNode = context.nodeModel.getNodeById({
id: source.parent,
});
const resolver = type.getFields()[fieldName].resolve;
return await resolver(mdxNode, args, context, {
fieldName,
});
};
exports.onPreInit = () => {
console.log(`=====\nBuilding subsite: ${SUBSITE}\n=====`);
};
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
if (SUBSITE === 'blog') {
await createBlogPages({ graphql, createPage });
await createTagPages({ graphql, createPage });
}
if (SUBSITE === 'slides') {
await createSlidesPages({ graphql, createPage });
}
};
exports.onCreatePage = ({ page, actions }) => {
const { createPage, deletePage } = actions;
moveSubsitePage(page, { createPage, deletePage });
};
exports.onCreateNode = ({
node,
actions,
getNode,
createNodeId,
createContentDigest,
}) => {
const { createNode, createNodeField, createParentChildLink } = actions;
createTimeToReadNodeField(node, { createNodeField });
if (SUBSITE === 'slides') {
createDeckNode(node, {
getNode,
createNodeId,
createContentDigest,
createNode,
createParentChildLink,
});
}
};
exports.onCreateWebpackConfig = ({ getConfig, actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
'~': path.resolve(__dirname, 'src/'),
},
extensions: ['.ts', '.tsx', '.js'],
},
});
if (getConfig().mode === 'production') {
actions.setWebpackConfig({
devtool: false,
});
}
};
exports.createSchemaCustomization = ({ actions, schema }) => {
actions.createTypes(
schema.buildObjectType({
name: 'Deck',
fields: {
id: { type: 'ID!' },
slug: {
type: 'String!',
},
frontmatter: {
type: 'MdxFrontmatter',
resolve: mdxResolverPassthrough('frontmatter'),
},
body: {
type: 'String!',
resolve: mdxResolverPassthrough('body'),
},
},
interfaces: ['Node'],
}),
);
};