forked from polkadot-developers/substrate-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathon-create-node.js
30 lines (27 loc) · 849 Bytes
/
on-create-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
const { createFilePath } = require('gatsby-source-filesystem');
const addSlugFieldToMarkdown = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
const filepaths = createFilePath({ node, getNode, basePath: `` })
.split('/')
.filter(pathElement => pathElement);
const slug = filepaths[filepaths.length - 1];
createNodeField({
node,
name: `slug`,
value: slug,
});
};
const addPathFieldToMarkdown = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
// get path from /content/md/en folder and remove "/docs" prefix for /md/en/docs/* md
const path = createFilePath({ node, getNode, basePath: `en` }).replace(/^(\/docs)/, '');
createNodeField({
node,
name: `path`,
value: path,
});
};
module.exports = {
addSlugFieldToMarkdown,
addPathFieldToMarkdown,
};