Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access data files from source folder #1969

Merged
merged 3 commits into from
Jul 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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