-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
109 lines (88 loc) · 2.69 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
104
105
106
107
108
109
"use strict";
const fetch = require(`./fetch`);
const normalize = require(`./normalize`);
const typePrefix = `wordpress__`;
const refactoredEntityTypes = {
post: `${typePrefix}POST`,
page: `${typePrefix}PAGE`,
tag: `${typePrefix}TAG`,
category: `${typePrefix}CATEGORY`
/* If true, will output many console logs. */
};let _verbose;
let _siteURL;
let _useACF = true;
let _hostingWPCOM;
let _auth;
let _perPage;
let _excludedRoutes;
exports.sourceNodes = async ({ boundActionCreators, getNode, store, cache, createNodeId }, {
baseUrl,
protocol,
hostingWPCOM,
useACF = true,
auth = {},
verboseOutput,
perPage = 100,
searchAndReplaceContentUrls = {},
excludedRoutes = []
}) => {
const { createNode } = boundActionCreators;
_verbose = verboseOutput;
_siteURL = `${protocol}://${baseUrl}`;
_useACF = useACF;
_hostingWPCOM = hostingWPCOM;
_auth = auth;
_perPage = perPage;
_excludedRoutes = excludedRoutes;
let entities = await fetch({
baseUrl,
_verbose,
_siteURL,
_useACF,
_hostingWPCOM,
_auth,
_perPage,
_excludedRoutes,
typePrefix,
refactoredEntityTypes
});
// Normalize data & create nodes
// Remove ACF key if it's not an object
entities = normalize.normalizeACF(entities);
// Creates entities from object collections of entities
entities = normalize.normalizeEntities(entities);
// Standardizes ids & cleans keys
entities = normalize.standardizeKeys(entities);
// Converts to use only GMT dates
entities = normalize.standardizeDates(entities);
// Lifts all "rendered" fields to top-level.
entities = normalize.liftRenderedField(entities);
// Exclude entities of unknown shape
entities = normalize.excludeUnknownEntities(entities);
// Creates Gatsby IDs for each entity
entities = normalize.createGatsbyIds(createNodeId, entities);
// Creates links between authors and user entities
entities = normalize.mapAuthorsToUsers(entities);
// Creates links between posts and tags/categories.
entities = normalize.mapPostsToTagsCategories(entities);
// Creates links between tags/categories and taxonomies.
entities = normalize.mapTagsCategoriesToTaxonomies(entities);
// Creates links from entities to media nodes
entities = normalize.mapEntitiesToMedia(entities);
// Downloads media files and removes "sizes" data as useless in Gatsby context.
entities = await normalize.downloadMediaFiles({
entities,
store,
cache,
createNode,
_auth
});
// Search and replace Content Urls
entities = normalize.searchReplaceContentUrls({
entities,
searchAndReplaceContentUrls
});
// creates nodes for each entry
normalize.createNodesFromEntities({ entities, createNode });
return;
};