fix: removed all guide bits from gatsby

This commit is contained in:
Mrugesh Mohapatra
2019-07-25 13:53:42 +05:30
committed by mrugesh
parent 7bc6367d68
commit 0124e7556d
27 changed files with 6 additions and 1493 deletions

View File

@ -1,66 +0,0 @@
const crypto = require('crypto');
const path = require('path');
const commonREs = require('../../utils/regEx');
const readDir = require('../../utils/readDir');
const { isAStubRE } = commonREs;
// default locale to english for testing
const { NODE_ENV: env, LOCALE: locale = 'english' } = process.env;
const guideDir = `../../../${
env === 'production' ? 'guide' : 'mock-guide'
}/${locale}`;
const pagesDir = path.resolve(__dirname, guideDir);
const indexMdRe = new RegExp(`\\${path.sep}index.md$`);
function withGuidePrefix(str) {
return `/guide${str}`;
}
exports.createNavigationNode = function createNavigationNode(node) {
const {
fileAbsolutePath,
frontmatter: { title },
internal: { content },
parent
} = node;
const nodeDir = path.resolve(fileAbsolutePath).replace(indexMdRe, '');
const dashedName = nodeDir.split(path.sep).slice(-1)[0];
const nodePath = nodeDir
.split(pagesDir)[1]
.split(path.sep)
.join('/');
const parentPath = nodePath
.split('/')
.slice(0, -1)
.join('/');
const categoryChildren = readDir(nodeDir);
const navNode = {
categoryChildren,
hasChildren: !!categoryChildren.length,
dashedName,
isStubbed: isAStubRE.test(content),
path: withGuidePrefix(nodePath),
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 };
};

View File

@ -1,85 +0,0 @@
const path = require('path');
const { expect } = require('chai');
const { createNavigationNode } = require('./create-navigation-node');
describe('fcc-create-nav-data', () => {
describe('create-vanigation-node', () => {
const mockNode = {
internal: {
content:
'---\ntitle: File Writing\n---\n## File Writing\n\nThis is a stub.' +
" <a href='https://github.com/freeCodeCamp/guides/tree/master/src/" +
"pages/php/functions/files/writing/index.md' target='_blank' " +
"rel='nofollow'>Help our community expand it</a>.\n\n<a href=" +
"'https://github.com/freeCodeCamp/freeCodeCamp/blob/master/docs/style-guide-for-guide-articles.md' " +
"target='_blank' rel='nofollow'>This quick style guide will help " +
'ensure your pull request gets accepted</a>.\n\n<!-- The article ' +
'goes here, in GitHub-flavored Markdown. Feel free to add YouTube ' +
'videos, images, and CodePen/JSBin embeds -->\n\n#### More ' +
'Information:\n<!-- Please add any articles you think might be ' +
'helpful to read before writing the article -->\n'
},
frontmatter: {
title: 'File Writing'
},
fileAbsolutePath: path.resolve(
__dirname,
'../../../mock-guide/english/php/functions/files/file-writing/index.md'
)
};
const result = createNavigationNode(mockNode);
it('should return an object', () => {
expect(result).to.be.an('object');
});
it('node.children should be an array', () => {
expect(result.categoryChildren).to.be.an('array');
});
it('node.dashedName should equal the containing folder name', () => {
expect(result.dashedName).equal('file-writing');
});
it(
'node.path should equal the file path from pagesDir, ' +
'prefixed with `/guide`',
() => {
expect(result.path).to.equal('/guide/php/functions/files/file-writing');
}
);
it(
'node.parentPath should equal the path of the parent page, ' +
'prefixed with `/guide`',
() => {
expect(result.parentPath).to.equal('/guide/php/functions/files');
}
);
it('node.title should equal srcNode.frontmatter.title', () => {
expect(result.title).to.equal(mockNode.frontmatter.title);
});
it('node.isStubbed should be a boolean', () => {
expect(result.isStubbed).to.be.a('boolean');
});
it('node.isStubbed should be true for a stubbed article', () => {
expect(result.isStubbed).to.equal(true);
});
it('node.isStubbed should be false for a non-stubbed article', () => {
const notAStub = {
...mockNode,
internal: {
content: 'this is not a stub article. Infact, it is very informative'
}
};
const result = createNavigationNode(notAStub);
expect(result.isStubbed).to.equal(false);
});
});
});

View File

@ -1,21 +0,0 @@
const { createNavigationNode } = require('./create-navigation-node');
exports.onCreateNode = function createNavDataOnCreateNode({ actions, node }) {
const {
internal: { type },
fields
} = node;
if (
type === 'MarkdownRemark' &&
fields &&
fields.nodeIdentity === 'guideMarkdown'
) {
if (node.fileAbsolutePath.includes('LICENSE.md')) {
return null;
}
const { createNode } = actions;
const navNode = createNavigationNode(node);
return createNode(navNode);
}
return null;
};

View File

@ -1,218 +0,0 @@
{
"name": "fcc-create-nav-data",
"version": "0.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"assertion-error": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz",
"integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw=="
},
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"brace-expansion": {
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
"browser-stdout": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz",
"integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw=="
},
"chai": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz",
"integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==",
"requires": {
"assertion-error": "^1.1.0",
"check-error": "^1.0.2",
"deep-eql": "^3.0.1",
"get-func-name": "^2.0.0",
"pathval": "^1.1.0",
"type-detect": "^4.0.5"
}
},
"check-error": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz",
"integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII="
},
"commander": {
"version": "2.15.1",
"resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz",
"integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"deep-eql": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz",
"integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==",
"requires": {
"type-detect": "^4.0.0"
}
},
"diff": {
"version": "3.5.0",
"resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz",
"integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA=="
},
"escape-string-regexp": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"get-func-name": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz",
"integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE="
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"growl": {
"version": "1.10.5",
"resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz",
"integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA=="
},
"has-flag": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
},
"he": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz",
"integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0="
},
"inflight": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"minimatch": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "^1.1.7"
}
},
"minimist": {
"version": "0.0.8",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
},
"mkdirp": {
"version": "0.5.1",
"resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"requires": {
"minimist": "0.0.8"
}
},
"mocha": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz",
"integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==",
"requires": {
"browser-stdout": "1.3.1",
"commander": "2.15.1",
"debug": "3.1.0",
"diff": "3.5.0",
"escape-string-regexp": "1.0.5",
"glob": "7.1.2",
"growl": "1.10.5",
"he": "1.1.1",
"minimatch": "3.0.4",
"mkdirp": "0.5.1",
"supports-color": "5.4.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
},
"pathval": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz",
"integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA="
},
"supports-color": {
"version": "5.4.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
"integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
"requires": {
"has-flag": "^3.0.0"
}
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
"integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g=="
},
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}
}
}

View File

@ -1,13 +0,0 @@
{
"name": "fcc-create-nav-data",
"private": true,
"version": "0.0.1",
"scripts": {
"test": "mocha -R spec \"./{,!(node_modules)/**/}*.test.js\"",
"test:watch": "mocha -R spec \"./{,!(node_modules)/**/}*.test.js\" --watch"
},
"dependencies": {
"chai": "^4.1.2",
"mocha": "^5.0.5"
}
}