-
Notifications
You must be signed in to change notification settings - Fork 37
/
gatsby-node.js
34 lines (30 loc) · 872 Bytes
/
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
require('dotenv').config()
let algoliasearch = require('algoliasearch')
const path = require('path')
const removeAccents = require('remove-accents')
const fixNameB = name =>
removeAccents(name)
.split(' ')
.join('-')
.toLowerCase()
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
let client = algoliasearch('UEHWANDHH2', process.env.ALGOLIA_KEY)
let index = client.initIndex('cities')
var browser = await index.browseAll()
return new Promise((resolve, reject) => {
browser.on('result', function onResult(content) {
resolve(
content.hits.forEach(city => {
createPage({
path: `/${fixNameB(city.name)}`,
component: path.resolve(`src/templates/city.js`),
context: {
city
}
})
})
)
})
})
}