-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
56 lines (46 loc) · 1.54 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
const assert = require("assert");
const gatsbySourceMedium = require("gatsby-source-medium/gatsby-node");
const { createClient } = require("contentful");
const getCompanyInformationEntry = (entry) =>
entry.sys.contentType.sys.id === "companyInformation";
const LandingTemplate = require.resolve("./src/templates/Home.tsx");
const ModalTemplate = require.resolve("./src/templates/Modal.tsx");
const NotFoundTemplate = require.resolve("./src/templates/NotFound.tsx");
exports.sourceNodes = async (gatsbyConfig) => {
const { CONTENTFUL_ACCESS_TOKEN, CONTENTFUL_SPACE_ID } = process.env;
const client = createClient({ space: CONTENTFUL_SPACE_ID, accessToken: CONTENTFUL_ACCESS_TOKEN });
const { items } = await client.getEntries();
const companyInformation = items.find(getCompanyInformationEntry);
assert(
companyInformation,
"Can't fetch `companyInformation` entry from Contentful"
);
const { mediumUser = "@medium" } = companyInformation.fields;
await gatsbySourceMedium.sourceNodes(gatsbyConfig, { username: mediumUser });
};
exports.createPages = async ({ actions }, themeOptions) => {
const { landingPath = "/" } = themeOptions;
const { createPage } = actions;
createPage({
path: landingPath,
component: LandingTemplate,
});
createPage({
path: "/modal",
component: ModalTemplate,
});
createPage({
path: "/404",
component: NotFoundTemplate,
});
};
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
assert: require.resolve("assert"),
},
fallback: { fs: false },
},
});
};