-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
38 lines (33 loc) · 1.22 KB
/
gatsby-node.js
File metadata and controls
38 lines (33 loc) · 1.22 KB
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
const APISiteData = 'https://kerckhoff.dailybruin.com/api/packages/flatpages/internal.design.dailybruin.com/';
const axios = require('axios');
const { lowercaseAndDash } = require('./helper');
exports.createPages = async ({ actions: { createPage } }) => {
const response = await axios.get(APISiteData);
const siteData = response.data;
const { data } = siteData;
const { navigation } = data['Navigation.aml'];
const pathArray = [];
const recursiveGenPagesFromNavigation = (nav) => {
nav.forEach((navItem) => {
if (navItem.type === 'menu_item') {
pathArray.push(lowercaseAndDash(navItem.value));
const pathCreated = `/${pathArray.join('/')}`;
createPage({
path: pathCreated,
component: require.resolve('./src/templates/doc-page/index.jsx'),
context: {
pageData: data[`${navItem.value}.aml`],
pageNav: navigation,
path: `/${pathArray.join('/')}`,
},
});
pathArray.pop();
} else {
pathArray.push(lowercaseAndDash(navItem.value.menu_item));
recursiveGenPagesFromNavigation(navItem.value.submenus);
pathArray.pop();
}
});
};
recursiveGenPagesFromNavigation(navigation);
};