-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
96 lines (85 loc) · 2.61 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
const projects = require('./data/projects.json')
const workHistory = require('./data/workhistory.json')
const uses = require('./data/uses.json')
const path = require('path')
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
'@components': path.resolve(__dirname, 'src/components'),
},
},
})
}
exports.sourceNodes = ({ actions, createNodeId, createContentDigest }) => {
projects.forEach(Project => {
const node = {
name: Project.name,
description: Project.description,
thumbnailPath: Project.thumbnailPath,
demoUrl: Project.demoUrl,
sourceUrl: Project.sourceUrl,
id: createNodeId(`Project-${Project.name}`),
internal: {
type: 'Project',
contentDigest: createContentDigest(Project),
},
}
actions.createNode(node)
})
workHistory.forEach(WorkHistory => {
const node = {
employer: WorkHistory.employer,
title: WorkHistory.title,
dateRange: WorkHistory.dateRange,
description: WorkHistory.description,
id: createNodeId(`WorkHistory-${WorkHistory.employer}`),
internal: {
type: 'WorkHistory',
contentDigest: createContentDigest(WorkHistory),
},
}
actions.createNode(node)
})
uses.forEach(use => {
const node = {
section: use.section,
entries: use.entries,
id: createNodeId(`Uses-${use.section}`),
internal: {
type: 'Uses',
contentDigest: createContentDigest(use),
},
}
actions.createNode(node)
})
}
exports.createPages = async ({ graphql, actions, reporter }) => {
const { createPage } = actions
const result = await graphql(`
{
allSanityBlogPost {
nodes {
date(formatString: "YYYY/MM/DD")
title
slug
id
}
}
}
`)
if (result.errors) {
throw result.errors
}
const blogPosts = result.data.allSanityBlogPost.nodes || []
blogPosts.forEach(post => {
const { id, slug } = post
const path = `/blog/${slug}`
reporter.info(`Creating blog post page: ${path}`)
createPage({
path,
component: require.resolve('./src/templates/blogPost.js'),
context: { id },
})
})
}