-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
133 lines (125 loc) · 2.42 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
const path = require(`path`)
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type Mdx implements Node {
frontmatter: MdxFrontmatter!
}
type MdxFrontmatter {
address: String
beers: [String]
city: String
coordinates: String
country: String
date(
difference: String
formatString: String
fromNow: Boolean
locale: String
): Date
facebook: String
googlemaps: String
instagram: String
locations: [String]
name: String
open: Boolean
path: String
title: String
twitter: String
type: [String]
untappd: String
website: String
}
`
createTypes(typeDefs)
}
exports.createPages = async ({ actions, graphql, reporter }) => {
const { createPage } = actions
const blogPostTemplate = path.resolve(`src/templates/BlogPostTemplate.js`)
const entryPostTemplate = path.resolve(`src/templates/Entry.js`)
const result = await graphql(`
{
blogPosts: allMdx(
filter: { fileAbsolutePath: { regex: "/blog/" } }
sort: { order: DESC, fields: [frontmatter___date] }
limit: 1000
) {
edges {
node {
id
body
excerpt
mdxAST
slug
frontmatter {
date
images
path
title
}
}
}
}
entries: allMdx(
filter: {
fileAbsolutePath: { regex: "/entries/" }
frontmatter: { open: { ne: null } }
}
) {
edges {
node {
id
excerpt
slug
body
fileAbsolutePath
frontmatter {
title
path
date
open
address
beers
city
coordinates
country
facebook
googlemaps
images
instagram
name
opening_date
twitter
type
untappd
website
location {
coordinates
}
}
rawBody
}
}
}
}
`)
// Handle errors
if (result.errors) {
reporter.panicOnBuild(`Error while running GraphQL query.`)
return
}
result.data.blogPosts.edges.forEach(({ node }) => {
createPage({
path: `blog/${node.slug}`,
component: blogPostTemplate,
context: { id: node.id }, // additional data can be passed via context
})
})
result.data.entries.edges.forEach(({ node }) => {
createPage({
path: node.slug,
component: entryPostTemplate,
context: { id: node.id }, // additional data can be passed via context
})
})
}