Permalink
Browse files

Add default post propertiees

  • Loading branch information...
1 parent c782476 commit f3fb101c1a488ab99bcd957a5ad42aa95c1f81fe @ben-ng committed Jul 29, 2013
Showing with 20 additions and 9 deletions.
  1. +18 −8 lib/index.js
  2. +1 −1 package.json
  3. +1 −0 test/import.js
View
@@ -6,7 +6,16 @@ var _ = require('lodash')
, yaml = require('js-yaml')
, async = require('async')
, kitten
- , mdExts = ['md', 'mdown', 'markdown'];
+ , mdExts = ['md', 'mdown', 'markdown']
+ , requiredFields = [
+ 'layout'
+ , 'title'
+ , 'date'
+ ]
+ , defaults = {
+ published: true
+ , categories: []
+ };
kitten = {
load: function (path, cb) {
@@ -25,12 +34,7 @@ kitten = {
}
, _loadFile: function (file, cb) {
fs.readFile(file, function (err, data) {
- var requiredFields = [
- 'layout'
- , 'title'
- , 'date'
- ]
- , resp
+ var resp
, header
, content
, basename = path.basename(file)
@@ -71,9 +75,15 @@ kitten = {
}
}
- // Parse date into a javascript Date object
+ // Set defaults
+ header = _.extend({}, defaults, header);
+
+ // Parse `date` into a javascript Date object
header.date = new Date(header.date);
+ // Make sure `published` is a bool
+ header.published = (header.published == 'true' || header.published === true);
+
cb(null, _.extend({}, header, {content: content}));
});
}
View
@@ -10,7 +10,7 @@
"scotch",
"blog"
],
- "version": "0.0.1",
+ "version": "0.0.2",
"repository": {
"type": "git",
"url": "git://github.com/ben-ng/kitten-js.git"
View
@@ -15,6 +15,7 @@ var kitten = require('../lib')
, date: new Date('2112-05-19 21:12')
, comments: false
, categories: ['Depressing', 'Fleeting']
+ , published: true
, content: '# Lost Souls\n\
\n\
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.'

0 comments on commit f3fb101

Please sign in to comment.