-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
78 lines (69 loc) · 2.21 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
const { createRemoteFileNode } = require('gatsby-source-filesystem');
/** @param {import('gatsby').CreateSchemaCustomizationArgs }*/
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
createTypes(`
type DevArticles implements Node {
id: ID!
article: Article
featuredImg: File @link(from: "fields.featuredImg")
}
type Article {
url: String
title: String
tags: [String]
description: String
cover_image: String
social_image: String
published_at(
difference: String
formatString: String
fromNow: Boolean
locale: String
): Date
positive_reactions_count: Int
}
`);
};
/** @param {import('gatsby').CreateNodeArgs } args */
exports.onCreateNode = async (args) => {
const { node, actions, getCache, createNodeId } = args;
const { createNode, createNodeField } = actions;
if (
node.internal.type === 'DevArticles' &&
(node.article.cover_image || node.article.social_image)
) {
const fileNode = await createRemoteFileNode({
url: node.article.cover_image || node.article.social_image,
parentNodeId: node.id,
createNode,
createNodeId,
getCache,
});
if (fileNode) {
const nodeField = { node, name: 'featuredImg', value: fileNode.id };
createNodeField(nodeField);
}
}
};
const path = require('path');
/** @param {import('gatsby').CreateWebpackConfigArgs }*/
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
'@assets': path.resolve(__dirname, 'src/assets'),
'@components': path.resolve(__dirname, 'src/components'),
'@data': path.resolve(__dirname, 'src/data'),
'@hooks': path.resolve(__dirname, 'src/hooks'),
'@images': path.resolve(__dirname, 'src/images'),
'@i18n': path.resolve(__dirname, 'src/i18n'),
'@pages': path.resolve(__dirname, 'src/pages'),
'@sections': path.resolve(__dirname, 'src/sections'),
'@theme': path.resolve(__dirname, 'src/theme'),
'@typescript': path.resolve(__dirname, 'src/typescript'),
'@utils': path.resolve(__dirname, 'src/utils'),
},
},
});
};