forked from appsody/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
57 lines (51 loc) · 1.58 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
const path = require(`path`)
const fetch = require('node-fetch');
const fs = require('file-system');
// Add URLs to v2 indexes to this array for them to be rendered on the website
// If the index does not need to be downloaded, place the index.yaml in src/data/indexes
// Note: this is only for developement add URLs to /ci/get-indexes.sh to affect production
const indexURLs = [
'https://github.com/appsody/stacks/releases/latest/download/stable-index.yaml',
'https://github.com/appsody/stacks/releases/latest/download/incubator-index.yaml',
'https://github.com/appsody/stacks/releases/latest/download/experimental-index.yaml'
]
exports.onPreInit = () => {
indexURLs.forEach(url => {
fetch(url)
.then(res => res.text())
.then(body => {
const fileName = url.split('/').reverse()[0];
fs.writeFile(`src/data/indexes/${fileName}`, body);
})
})
}
exports.createPages = ({ actions, graphql }) => {
const { createPage, createRedirect } = actions
const docTemplate = path.resolve(`src/templates/docTemplate.js`)
return graphql(`
{
allMarkdownRemark {
edges {
node {
frontmatter {
path
}
}
}
}
}
`).then(result => {
if (result.errors) {
return Promise.reject(result.errors)
}
return result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.frontmatter.path,
component: docTemplate,
context: {
layout: "docs"
}, // additional data can be passed via context
})
})
})
}