-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
30 lines (29 loc) · 976 Bytes
/
index.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
/**
* @param {function} getStaticPaths - Function exported from component
* @param {function} actions - Function of the Gatsby Node APIs
* @param {Object} page - Object containing page properties
* * @returns {Function} Returns asynchronous function to create the pages using Gatsby Node APIs
*/
const createDynamicPages = async (getStaticPaths, actions, page) => {
if (!getStaticPaths) {
actions.createPage({
...page,
});
} else {
try {
const routes = await getStaticPaths();
for (route of routes?.paths) {
const staticPath = route.params.basePath + route.params.slug;
console.log('\x1b[32msuccess\x1b[0m', staticPath);
actions.createPage({
...page,
path: staticPath,
context: { staticProps: route?.staticProps },
});
}
} catch (err) {
console.error('\x1b[41mError gatsby-plugin-static-paths\x1b[0m', err);
}
}
};
module.exports = createDynamicPages;