This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #187 from timaschew/refactor-gulp-templates
improve gulp template task, provide support for subdirectories
- Loading branch information
Showing
2 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
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 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,42 @@ | ||
var _ = require('lodash'); | ||
|
||
var DEFAULT_LANG = 'en'; | ||
var CONTENT_DIRECTORY = 'content'; | ||
|
||
// load template.json for given language, but use default language as fallback | ||
// for properties which are not present in the given language | ||
module.exports.loadTemplateJSON = function(lang) { | ||
var defaultJSON = require('../../' + CONTENT_DIRECTORY + '/' + DEFAULT_LANG + '/template.json'); | ||
var templateJSON = require('../../' + CONTENT_DIRECTORY + '/' + lang + '/template.json'); | ||
var finalJSON = _.cloneDeep(defaultJSON); | ||
_.forEach(templateJSON, function(value, key) { | ||
finalJSON[key] = value; | ||
}); | ||
return finalJSON; | ||
}; | ||
|
||
// load all the files for a given language | ||
// return an object with | ||
// - the origin srcPath | ||
// - the filename without extension | ||
// - the filepath as an array, reduced by the starting './content' directory | ||
module.exports.loadMdFiles = function(contentFiles, lang) { | ||
var templateFiles = _.where(contentFiles, function(str) { // return list of content files in this language alone | ||
return str.indexOf('./' + CONTENT_DIRECTORY + '/' + lang) > -1; | ||
}); | ||
|
||
var templateFilesInThisLang = _.map(templateFiles, function(str) { // expand the file list to include the extrapolated filename | ||
var obj = {}; | ||
obj.srcPath = str; | ||
obj.filepathArray = str.split('/'); | ||
obj.filepathArray = _.filter(obj.filepathArray, function(pathPart) { | ||
if (pathPart !== '.' && pathPart !== 'content') { | ||
return true; | ||
} | ||
}); | ||
obj.filename = obj.filepathArray[obj.filepathArray.length-1]; | ||
obj.filename = obj.filename.split('.md')[0]; | ||
return obj; | ||
}); | ||
return templateFilesInThisLang; | ||
}; |