grunt-pages
Advanced tools
Comparing version 0.8.3 to 0.9.0
{ | ||
"name": "grunt-pages", | ||
"version": "0.8.3", | ||
"version": "0.9.0", | ||
"description": "Grunt task to create pages using markdown and templates", | ||
@@ -13,3 +13,4 @@ "main": "Gruntfile.js", | ||
"rss": "~0.2.0", | ||
"lodash": "~2.2.0" | ||
"lodash": "~2.2.0", | ||
"node-fs": "~0.1.7" | ||
}, | ||
@@ -16,0 +17,0 @@ "devDependencies": { |
@@ -17,3 +17,3 @@ # grunt-pages | ||
Then add this line to your project's `Gruntfile.js` gruntfile: | ||
Then add this line to your project's `Gruntfile.js` Gruntfile: | ||
@@ -55,3 +55,3 @@ ```javascript | ||
The only property that is not interpreted literally is the `date`. It is used as a `dateString` when constructing a [Date object](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date) in JavaScript, and must be in a [parseable format](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/parse). | ||
The only property that is not interpreted literally is the `date`. If it is specified, it is used as a `dateString` when constructing a [Date object](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date) in JavaScript, and must be in a [parseable format](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/parse). If unspecified, the post's date will be the result of constructing a Date object using the post's last modified time. | ||
@@ -92,5 +92,5 @@ #### Syntax Highlighting | ||
The [jade](https://github.com/visionmedia/jade) or [ejs](https://github.com/visionmedia/ejs) layout template used for each post. The post metadata will be stored in a `post` object to be rendered in the layout template. [Here](https://github.com/CabinJS/grunt-pages/blob/master/test/fixtures/integration/input/jade/layouts/post.jade) is an example post layout template. | ||
The [jade](https://github.com/visionmedia/jade) or [EJS](https://github.com/visionmedia/ejs) layout template used for each post. The post metadata will be stored in a `post` object to be rendered in the layout template. [Here](https://github.com/CabinJS/grunt-pages/blob/master/test/fixtures/integration/input/target2/layouts/post.jade) is an example post layout template. | ||
**Note: you can run grunt-pages with the `--debug` flag set to see all the data passed to templates for rendering** | ||
**Note: you can run grunt-pages with the `--debug` flag set to see all the data passed to templates for rendering**. | ||
@@ -107,3 +107,3 @@ #### url | ||
The folder where the ejs or jade source pages of your website are located. These pages have access to each post's `content` and metadata properties via a `posts` array. Additionally, pages have access to their own filename(without extension) via the `currentPage` variable to optionally display it differently when linking to pages. All of the files in this folder are generated in the `dest` folder maintaining the same relative path from `pageSrc`. | ||
The folder where the ejs or jade source pages of your website are located. These pages have access to each post's `content` and metadata properties via a `posts` array. Additionally, pages have access to their own filename(without extension) via the `currentPage` variable to optionally display it differently when linking to pages. All of the files in this folder are generated in the `dest` folder maintaining the same relative path from `options.pageSrc`. | ||
@@ -144,3 +144,3 @@ #### data | ||
A function that takes a `url` as a parameter and returns a formatted url string. This is primarily used to remove special characters and replace whitespace. | ||
A function that takes a `url` as a parameter and returns a formatted URL string. This is primarily used to remove special characters and replace whitespace. | ||
@@ -234,3 +234,3 @@ #### rss | ||
The location of the layout template which is used for each list page. This page will not be rendered as a regular page if inside the options.pageSrc folder and instead will be rendered as the root list page with the first post group. [Here](https://github.com/CabinJS/grunt-pages/blob/master/test/fixtures/integration/input/jade/pages/blog/index.jade) is a sample `listPage` template. This template has access to the following variables: | ||
The location of the layout template which is used for each list page. This page will not be rendered as a regular page if `options.pageSrc` is specified. Instead it will be rendered as the root paginated list page with the first post group instead of all the posts. [Here](https://github.com/CabinJS/grunt-pages/blob/master/test/fixtures/integration/input/target2/pages/blog/index.jade) is a sample `listPage` template. This template has access to the following variables: | ||
@@ -240,3 +240,3 @@ ###### posts | ||
An array of post objects assigned to this page which each contain the `content` and metadata properties of the post. | ||
An array of post objects assigned to this page which each contain the post `content` and other metadata properties of the post. | ||
@@ -251,3 +251,3 @@ ###### pages | ||
A reference to the index of the page currently being rendered. This can be used to display the current page differently than the rest of the pages in a list, or to display links to the surrounding pages based on their position relative to the `currentIndex`. | ||
A reference to the index of the list page currently being rendered. This can be used to display the current page differently than the rest of the pages in a list, or to display links to the surrounding pages based on their position relative to the `currentIndex`. | ||
@@ -266,3 +266,3 @@ ##### pagination.url | ||
Default: `Group by postsPerPage` | ||
Default: `Group by options.pagination.postsPerPage` | ||
@@ -359,6 +359,8 @@ ```js | ||
The file extension of the template engine to be used. This option filters template files in the `pageSrc` folder when developing a grunt-pages configuration for multiple template engines. | ||
The file extension of the template engine to be used. This option filters template files in the `options.pageSrc` folder when developing a grunt-pages configuration for multiple template engines. | ||
# Changelog | ||
**0.8.3** - Posts without the `date` specified now default to using the post's last modified time as the date thanks to [@danburzo](https://github.com/danburzo). Fixed bug where draft posts in nested folders weren't ignored properly. | ||
**0.8.2** - Temporarily reverted bug fix as caching issues resulted from code change. | ||
@@ -365,0 +367,0 @@ |
@@ -10,3 +10,3 @@ /* | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
@@ -18,2 +18,3 @@ var url = require('url'); | ||
var marked = require('marked'); | ||
var fs = require('node-fs'); | ||
var pygmentize = require('pygmentize-bundled'); | ||
@@ -65,3 +66,3 @@ var RSS = require('rss'); | ||
var unmodifiedPosts = []; | ||
var cacheFile = path.normalize(__dirname + '/../.' + this.target + '-post-cache.json'); | ||
var cacheFile = path.normalize(process.cwd() + '/.grunt/grunt-pages/' + this.target + '-post-cache.json'); | ||
if (fs.existsSync(cacheFile)) { | ||
@@ -130,3 +131,3 @@ unmodifiedPosts = lib.getUnmodifiedPosts(JSON.parse(fs.readFileSync(cacheFile)).posts); | ||
token.text.toLowerCase().replace(/[^\w]+/g, '-') + | ||
'"class="anchor" href="#' + | ||
'" class="anchor" href="#' + | ||
token.text.toLowerCase().replace(/[^\w]+/g, '-') + | ||
@@ -362,2 +363,6 @@ '"><span class="header-link"></span></a>' + | ||
if (!fs.existsSync(path.dirname(cacheFile))) { | ||
fs.mkdirSync(path.dirname(cacheFile), '0777', true); | ||
} | ||
fs.writeFileSync(cacheFile, JSON.stringify(cachedPosts)); | ||
@@ -479,21 +484,29 @@ | ||
var layoutString = fs.readFileSync(_this.data.layout, 'utf8'); | ||
var fn = templateEngine.compile(layoutString, { pretty: true, filename: _this.data.layout }); | ||
var fn = templateEngine.compile(layoutString, { pretty: grunt.option('debug') ? true : false, filename: _this.data.layout }); | ||
var postDests = []; | ||
templateData.posts.forEach(function (post) { | ||
_(templateData.posts) | ||
// Remove the dest property from the posts now that they are generated | ||
.each(function (post) { | ||
postDests.push(post.dest); | ||
delete post.dest; | ||
}) | ||
.each(function (post, currentIndex) { | ||
// Pass the post data to the template via a post object | ||
templateData.post = post; | ||
// Pass the post data to the template via a post object | ||
// adding the current index to allow for navigation between consecutive posts | ||
templateData.post = _.extend(_.cloneDeep(post), { currentIndex: currentIndex }); | ||
grunt.log.debug(JSON.stringify(templateData, null, ' ')); | ||
grunt.file.write(post.dest, fn(templateData)); | ||
grunt.log.ok('Created '.green + 'post'.blue + ' at: ' + post.dest); | ||
}); | ||
grunt.log.debug(JSON.stringify(lib.reducePostContent(templateData), null, ' ')); | ||
try { | ||
grunt.file.write(postDests[currentIndex], fn(templateData)); | ||
} catch (e) { | ||
console.log('\nData passed to ' + _this.data.layout.blue + ' post template:\n\n' + JSON.stringify(lib.reducePostContent(templateData), null, ' ').yellow + '\n'); | ||
grunt.fail.fatal(e.message); | ||
} | ||
grunt.log.ok('Created '.green + 'post'.blue + ' at: ' + postDests[currentIndex]); | ||
}); | ||
// Remove the post object from the templateData now that each post has been generated | ||
delete templateData.post; | ||
// Remove the dest property from the posts now that they are generated | ||
templateData.posts.forEach(function (post) { | ||
delete post.dest; | ||
}); | ||
}; | ||
@@ -510,3 +523,3 @@ | ||
var layoutString = fs.readFileSync(abspath, 'utf8'); | ||
var fn = templateEngine.compile(layoutString, { pretty: true, filename: abspath }); | ||
var fn = templateEngine.compile(layoutString, { pretty: grunt.option('debug') ? true : false, filename: abspath }); | ||
@@ -519,4 +532,9 @@ // Determine the page's destination by prepending the dest folder, then finding its relative location | ||
templateData.currentPage = path.basename(abspath, path.extname(abspath)); | ||
grunt.log.debug(JSON.stringify(templateData, null, ' ')); | ||
grunt.file.write(dest, fn(templateData)); | ||
grunt.log.debug(JSON.stringify(lib.reducePostContent(templateData), null, ' ')); | ||
try { | ||
grunt.file.write(dest, fn(templateData)); | ||
} catch (e) { | ||
console.log('\nData passed to ' + abspath.magenta + ' page template:\n\n' + JSON.stringify(lib.reducePostContent(templateData), null, ' ').yellow + '\n'); | ||
grunt.fail.fatal(e.message); | ||
} | ||
grunt.log.ok('Created '.green + 'page'.magenta + ' at: ' + dest); | ||
@@ -566,2 +584,24 @@ } | ||
/** | ||
* Reduces the content of posts to make --debug logging more readable | ||
* @param {Object} templateData Data to be passed to templates for rendering | ||
* @return {Object} Data to be logged in --debug output | ||
*/ | ||
lib.reducePostContent = function (templateData) { | ||
var templateDataClone = _.cloneDeep(templateData); | ||
if (templateDataClone.posts) { | ||
templateDataClone.posts.map(function (post) { | ||
return _.extend(post, { content: post.content.substr(0, 10) + '...' }); | ||
}); | ||
} | ||
if (templateDataClone.post) { | ||
templateDataClone.post.content = templateDataClone.post.content.substr(0, 10) + '...'; | ||
} | ||
return templateDataClone; | ||
}; | ||
/** | ||
* Default function to get post groups for each paginated page by grouping a specified number of posts per page | ||
@@ -616,3 +656,3 @@ * @param {Array} postCollection Collection of parsed posts with the content and metadata properties | ||
var layoutString = fs.readFileSync(listPage, 'utf8'); | ||
var fn = templateEngine.compile(layoutString, { pretty: true, filename: listPage }); | ||
var fn = templateEngine.compile(layoutString, { pretty: grunt.option('debug') ? true : false, filename: listPage }); | ||
@@ -634,4 +674,9 @@ pages.forEach(function (page, currentIndex) { | ||
grunt.log.debug(JSON.stringify(templateRenderData, null, ' ')); | ||
grunt.file.write(lib.getDestFromUrl(page.url), fn(templateRenderData)); | ||
grunt.log.debug(JSON.stringify(lib.reducePostContent(templateRenderData), null, ' ')); | ||
try { | ||
grunt.file.write(lib.getDestFromUrl(page.url), fn(templateRenderData)); | ||
} catch (e) { | ||
console.log('\nData passed to ' + listPage.magenta + ' paginated list page template:\n\n' + JSON.stringify(lib.reducePostContent(templateData), null, ' ').yellow + '\n'); | ||
grunt.fail.fatal(e.message); | ||
} | ||
grunt.log.ok('Created '.green + 'paginated'.rainbow + ' page'.magenta + ' at: ' + lib.getDestFromUrl(page.url)); | ||
@@ -638,0 +683,0 @@ }); |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
45939
654
426
0
9
+ Addednode-fs@~0.1.7
+ Addednode-fs@0.1.7(transitive)