feat(guide): Import guide in to the client app
This commit is contained in:
55
client/plugins/fcc-create-nav-data/create-navigation-node.js
Normal file
55
client/plugins/fcc-create-nav-data/create-navigation-node.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const crypto = require('crypto');
|
||||
const path = require('path');
|
||||
|
||||
const commonREs = require('../../utils/regEx');
|
||||
const readDir = require('../../utils/readDir');
|
||||
|
||||
const { isAStubRE } = commonREs;
|
||||
const pagesDir = path.resolve(__dirname, '../../src/pages/guide');
|
||||
|
||||
function withGuidePrefix(str) {
|
||||
return `/guide${str}`;
|
||||
}
|
||||
|
||||
exports.createNavigationNode = node => {
|
||||
const {
|
||||
fileAbsolutePath,
|
||||
frontmatter: { title },
|
||||
internal: { content },
|
||||
parent
|
||||
} = node;
|
||||
|
||||
const nodeDir = fileAbsolutePath.replace(/\/index\.md$/, '');
|
||||
const dashedName = nodeDir.split('/').slice(-1)[0];
|
||||
const [, path] = nodeDir.split(pagesDir);
|
||||
const parentPath = path
|
||||
.split('/')
|
||||
.slice(0, -1)
|
||||
.join('/');
|
||||
|
||||
const categoryChildren = readDir(nodeDir);
|
||||
const navNode = {
|
||||
categoryChildren,
|
||||
hasChildren: !!categoryChildren.length,
|
||||
dashedName,
|
||||
isStubbed: isAStubRE.test(content),
|
||||
path: withGuidePrefix(path),
|
||||
parentPath: withGuidePrefix(parentPath),
|
||||
title
|
||||
};
|
||||
|
||||
const gatsbyRequired = {
|
||||
id: fileAbsolutePath + ' >>> NavigationNode',
|
||||
parent,
|
||||
children: [],
|
||||
internal: {
|
||||
type: 'NavigationNode',
|
||||
contentDigest: crypto
|
||||
.createHash('md5')
|
||||
.update(JSON.stringify(navNode))
|
||||
.digest('hex')
|
||||
}
|
||||
};
|
||||
|
||||
return { ...navNode, ...gatsbyRequired };
|
||||
};
|
Reference in New Issue
Block a user