-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgatsby-node.js
171 lines (145 loc) · 4.11 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
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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
// You can delete this file if you're not using it
const path = require("path");
const axios = require("axios")
const { shapes } = require('./src/data/shapes')
// here's where we generate GraphQL nodes from our ArcGIS Hub data.json
exports.sourceNodes = async ({
actions,
createNodeId,
createContentDigest,
}) => {
const { createNode } = actions
// let routesUrl = `https://opendata.arcgis.com/datasets/82b2ce64ded34d728848961e342387d1_0.geojson`
// fetch the root data.json for the whole portal
// let root = await axios.get(routesUrl)
// for each node, register it with Gatsby
shapes.features.forEach((n, i) => {
let {properties, geometry} = n
let directionId;
// this is a hack & should be removed
if (properties.Direction === 'Eastbound') {
directionId = 1
}
if (properties.Direction === 'Westbound') {
directionId = 0
}
if (properties.Direction === 'Southbound') {
directionId = 0
}
if (properties.Direction === 'Northbound') {
directionId = 1
}
if (properties.Direction === 'Loop') {
directionId = 1
}
let props = {
id: i.toString(),
direction: properties.Direction,
directionId: directionId,
short: properties.RouteNum.toString(),
long: properties.RouteName,
orientation: properties.Orientatio,
localService: properties.LocalServi,
description: properties.Descriptio,
days: properties.OperationD,
frqWkBase: properties.BaseFreq1,
frqWkPeak: properties.PeakFreq1,
frqWkNight: properties.NightFreq1,
frqSaBase: properties.BaseFreq6,
frqSaNight: properties.NightFreq6,
frqSuBase: properties.BaseFreq7,
frqSuNight: properties.NightFreq7,
spanType: properties.SpanType,
routeType: properties.RouteType,
}
props.route = {type: "Feature", geometry: geometry}
let nodeContent = JSON.stringify(props)
let nodeMeta = {
parent: null,
children: [],
internal: {
type: `DdotRoute`,
mediaType: `text/html`,
content: nodeContent,
contentDigest: createContentDigest(nodeContent),
},
}
let node = Object.assign({}, props, nodeMeta)
createNode(node)
})
return
}
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /mapbox-gl/,
use: loaders.null()
}
]
}
});
}
};
exports.createPages = async ({ graphql, actions: { createPage } }) => {
let activeEnv = process.env.ACTIVE_ENV || process.env.NODE_ENV || "development";
const result = await graphql(`
{
postgres {
routes: allRoutesList(condition: {feedIndex: 44 }, orderBy: ROUTE_SORT_ORDER_ASC) {
agencyId
short: routeShortName
long: routeLongName
}
stops: allStopsList(condition: { feedIndex: 44 }, orderBy: STOP_ID_ASC ) {
feedIndex
stopId
stopCode
}
}
}
`);
result.data.postgres.routes.forEach(r => {
// we'll make a route page
createPage({
path: `/route/${r.short}`,
component: path.resolve("./src/templates/route-page.js"),
context: {
routeNo: r.short
}
});
createPage({
path: `/route/${r.short}/schedule`,
component: path.resolve("./src/templates/route-schedule-page.js"),
context: {
routeNo: r.short
}
});
createPage({
path: `/route/${r.short}/stops`,
component: path.resolve("./src/templates/route-stops-page.js"),
context: {
routeNo: r.short
}
});
});
result.data.postgres.stops.forEach(stop => {
let badCodes = ['01', '02', '03', '04']
if(badCodes.indexOf(stop.stopCode) === -1) {
createPage({
path: `/stop/${stop.stopCode}`,
component: path.resolve("./src/templates/stop-page.js"),
context: {
stopId: stop.stopId
}
});
}
});
};