Skip to content

Commit

Permalink
Merge pull request #1969 from gemedet/data
Browse files Browse the repository at this point in the history
Access data files from source folder
  • Loading branch information
Xuanwo authored Jul 3, 2016
2 parents 57412f7 + 7dcd841 commit cd9cfa3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/hexo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Hexo.prototype._generate = function(options) {
Locals.prototype.view_dir = pathFn.join(this.theme_dir, 'layout') + sep;

// Run before_generate filters
return this.execFilter('before_generate', null, {context: this})
return this.execFilter('before_generate', self.locals.get('data'), {context: this})
.then(function() {
self.locals.invalidate();
siteLocals = self.locals.toObject();
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/filter/before_generate/render_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var Promise = require('bluebird');

function renderPostFilter() {
function renderPostFilter(data) {
var self = this;

function renderPosts(model) {
Expand All @@ -12,6 +12,7 @@ function renderPostFilter() {

return Promise.map(posts, function(post) {
post.content = post._content;
post.site = {data: data};

return self.post.render(post.full_source, post).then(function() {
return post.save();
Expand Down
2 changes: 1 addition & 1 deletion test/scripts/box/box.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ describe('Box', function() {
var box = newBox('test');
var processor = sinon.spy();

box.watch().then(function() {
return box.watch().then(function() {
box.addProcessor(processor);
box.unwatch();

Expand Down
19 changes: 19 additions & 0 deletions test/scripts/filters/render_post.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,23 @@ describe('Render post', function() {
return page.remove();
});
});

it('use data variables', function() {
var id;

return Page.insert({
source: 'foo.md',
path: 'foo.html',
_content: '<p>Hello {{site.data.foo.name}}</p>'
}).then(function(page) {
id = page._id;
return renderPost({foo: {name: 'Hexo'}});
}).then(function() {
var page = Page.findById(id);
page.content.trim().should.eql('<p>Hello Hexo</p>');

return page.remove();
});
});

});
9 changes: 9 additions & 0 deletions test/scripts/hexo/hexo.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ describe('Hexo', function() {
});
});

it('call() - callback without args', function(callback) {
hexo.call('test', function(err, data) {
should.not.exist(err);
data.should.eql({});

callback();
});
});

it('call() - console not registered', function() {
var errorCallback = sinon.spy(function(err) {
err.should.have.property('message', 'Console `nothing` has not been registered yet!');
Expand Down

0 comments on commit cd9cfa3

Please sign in to comment.