-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
29 lines (24 loc) · 922 Bytes
/
Copy pathgatsby-node.js
File metadata and controls
29 lines (24 loc) · 922 Bytes
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
const path = require(`path`)
const fetch = require('node-fetch')
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions
const template = path.resolve(`src/components/GuidePage.js`)
const pages = ['Android', 'Chrome DevTools', 'Text Editors', 'Git & Github', 'iOS', 'Java & OOP', 'JQuery', 'Node js', 'Python', 'Web Design']
const fetchData = async (page) => {
const url = page.toLowerCase().replace(' js', 'js').replace(' & ', '&').replace(' ', '-')
const text = await fetch(`https://raw.githubusercontent.com/pennapps/guides/main/${page}.md`).then(file => file.text())
return {url, text}
}
const result = []
for (let page of pages) {
const data = await fetchData(page)
result.push(data)
}
result.forEach((page) => {
createPage({
path: `/${page.url}`,
component: template,
context: {text: page.text}
})
})
}