forked from Chalarangelo/30-seconds-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Combine remaining parsers into a single one, move into gatsby directory for ease of importing.
- Loading branch information
1 parent
15f80cd
commit 0fdceeb
Showing
9 changed files
with
73 additions
and
94 deletions.
There are no files selected for viewing
Submodule 30blog
updated
from a14b59 to adbf1f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import parseRequirements from './parseRequirements'; | ||
import createPages from './createPages'; | ||
import onCreateWebpackConfig from './onCreateWebpackConfig'; | ||
|
||
export { | ||
parseRequirements, | ||
createPages, | ||
onCreateWebpackConfig, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import glob from 'glob'; | ||
import path from 'path'; | ||
|
||
/** | ||
* Combines the given data JSONs, using the data files | ||
* of the content, returning an array of objects from the files. | ||
* @param {string} contentDir - The path to the content directory. | ||
*/ | ||
export const parseRequirables = contentDir => | ||
glob.sync(`${contentDir}/**/index.json`).map(file => | ||
glob.sync(`${file.slice(0, file.lastIndexOf('/'))}/!(index).json`) | ||
.reduce((acc, dataFile) => { | ||
acc.context = { ...acc.context, ...require(path.resolve(dataFile)) }; | ||
return acc; | ||
}, { ...require(path.resolve(file)), context: {} })); | ||
|
||
/** | ||
* Combines the given list of templates into an object. | ||
* @param {array} templates - An array of templates. | ||
* @param {string} templatesDir - The path to the template directory. | ||
*/ | ||
export const parseTemplates = (templates, templatesDir) => | ||
templates.reduce((acc, tmpl) => { | ||
acc[tmpl.name] = path.resolve(`${templatesDir}/${tmpl.path}`); | ||
return acc; | ||
}, {}); | ||
|
||
/* istanbul ignore next */ | ||
/** | ||
* Returns an object containing templates and requirables created by | ||
* combining the given template and content parameters. | ||
* @param {array} templates - An array of templates. | ||
* @param {string} templatesDir - The path to the template directory. | ||
* @param {string} contentDir - The path to the content directory. | ||
*/ | ||
const parseRequirements = (templates, templatesDir, contentDir) => ({ | ||
templates: parseTemplates(templates, templatesDir), | ||
requirables: parseRequirables(contentDir), | ||
}); | ||
|
||
export default parseRequirements; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters