-
-
Save patrickng/c138c4ac8e6891fecbfc to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var _ = require('lodash'); | |
var path = require('path'); | |
module.exports = function(grunt) { | |
// load the recipe template from the desired path | |
var projectTemplate = grunt.file.read('./src/templates/pages/project.hbs'); | |
// expand the data files and loop over each filepath | |
var pages = _.flatten(_.map(grunt.file.expand('./src/data/*.json'), function(filepath) { | |
// read in the data file | |
var data = grunt.file.readJSON(filepath); | |
// modify template injection with the page title and description | |
var modProjectTemplate = '---\n'; | |
modProjectTemplate += 'title: ' + data.project.projectTitle + '\n'; | |
modProjectTemplate += 'description: ' + data.project.meta.description + '\n'; | |
modProjectTemplate += '---\n'; | |
var concatModProjectTemplate = modProjectTemplate + projectTemplate; | |
// create a 'page' object to add to the 'pages' collection | |
return { | |
// the filename will determine how the page is named later | |
filename: path.basename(filepath, path.extname(filepath)), | |
// the data from the json file | |
data: data, | |
// add the recipe template as the page content | |
content: concatModProjectTemplate | |
}; | |
})); | |
// Project configuration. | |
grunt.initConfig({ | |
config: { | |
src: 'src', | |
dist: 'dist' | |
}, | |
assemble: { | |
pages: { | |
options: { | |
flatten: true, | |
assets: '<%= config.dist %>/assets', | |
layout: '<%= config.src %>/templates/layouts/default.hbs', | |
data: '<%= config.src %>/data/*.{json,yml}', | |
partials: '<%= config.src %>/templates/partials/*.hbs', | |
// add the pages array from above to the pages collection on the assemble options | |
pages: pages | |
}, | |
files: [ | |
// currently we need to trick grunt and assemble into putting the pages file into the correct | |
// place using this pattern | |
{ | |
dest: './dist/', | |
src: '!*' | |
} | |
] | |
} | |
} | |
}); | |
grunt.loadNpmTasks('assemble'); | |
grunt.registerTask('default', [ | |
'assemble' | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment