-
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.
- Loading branch information
nicolaslabbe
committed
Oct 5, 2016
1 parent
14cf168
commit 273a12a
Showing
5 changed files
with
67 additions
and
26 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,31 @@ | ||
import extend from 'extend' | ||
import { | ||
cmsData | ||
,config | ||
,dateSlug | ||
} from '../../' | ||
|
||
export function add(tpl, json, type, obj = {}, date = null, realType = 'draft') { | ||
let meta = config.meta.name | ||
|
||
// json[meta] = extend({}, json[meta]) | ||
var currentDate = (typeof date !== 'undefined' && date !== null && date !== '') ? date : new Date() | ||
var abeUrl = (type === 'publish') ? json[meta].link : cmsData.fileAttr.add(json[meta].link, 'd' + dateSlug(currentDate.toISOString())) + '' | ||
|
||
if(typeof json[meta].date === 'undefined' || json[meta].date === null) { | ||
json[meta].date = currentDate | ||
} | ||
json[meta].latest = { | ||
date: currentDate, | ||
abeUrl: abeUrl | ||
} | ||
json[meta].status = realType === 'reject' ? 'draft' : realType | ||
if(typeof json[meta][type] === 'undefined' || json[meta][type] === null) { | ||
json[meta][type] = JSON.parse(JSON.stringify(obj)) | ||
json[meta][type].date = currentDate | ||
json[meta][type].abeUrl = abeUrl | ||
} | ||
json[meta][type].latest = JSON.parse(JSON.stringify(obj)) | ||
json[meta][type].latest.date = currentDate | ||
json[meta][type].latest.abeUrl = abeUrl | ||
} |
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
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,33 @@ | ||
var chai = require('chai'); | ||
var path = require('path'); | ||
|
||
var config = require('../src/cli').config | ||
config.set({root: __dirname + '/fixtures/'}) | ||
|
||
var cmsData = require('../src/cli').cmsData; | ||
var Manager = require('../src/cli').Manager; | ||
var fse = require('fs-extra'); | ||
|
||
describe('Meta', function() { | ||
before( function(done) { | ||
Manager.instance.init() | ||
.then(function () { | ||
|
||
this.fixture = { | ||
tag: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf8') | ||
} | ||
done() | ||
|
||
}.bind(this)) | ||
}); | ||
|
||
/** | ||
* cmsData.meta.add | ||
* | ||
*/ | ||
it('cmsData.meta.add()', function() { | ||
var json = {abe_meta: {link: 'article.html'}}; | ||
cmsData.meta.add('article', json); | ||
chai.expect(json.abe_meta.date).to.not.be.undefined; | ||
}); | ||
}); |