forked from polkadot-developers/substrate-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-pages.js
48 lines (43 loc) · 1.11 KB
/
create-pages.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
const $path = require('path');
/*
Notes:
- all graphql function call returns a Promise
*/
const createDocsPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
{
allMarkdownRemark(filter: { fileAbsolutePath: { regex: "//(content)/(md)/(en)/(docs)/" } }) {
edges {
node {
fileAbsolutePath
fields {
path
slug
}
}
}
}
}
`);
if (!result || !result.data) return;
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
const { path, slug } = node.fields;
const filepaths = path.split('/').filter(pathElement => pathElement);
/* Create collection type based on folder name, for later use in template,
eg: `/<main-docs>/quick-start/` => collection: main-docs */
const [collection] = filepaths;
createPage({
path,
component: $path.resolve(`./src/templates/single.js`),
context: {
collection,
pagePath: path,
slug,
},
});
});
};
module.exports = {
createDocsPages,
};