Skip to content

Commit

Permalink
Fix issue #942 (#2348)
Browse files Browse the repository at this point in the history
* Fix issue #942

* Fix test cases

* Add test coverage

* Fix eslint

* Fix jscs failure
  • Loading branch information
kflu authored and NoahDragon committed Jan 18, 2017
1 parent 1da7ad5 commit c927811
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/plugins/helper/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ function openGraphHelper(options) {

images = images.map(function(path) {
if (!urlFn.parse(path).host) {
if (path[0] !== '/') path = '/' + path;
return config.url + path;
// resolve `path`'s absolute path relative to current page's url
// `path` can be both absolute (starts with `/`) or relative.
return urlFn.resolve(url || config.url, path);
}

return path;
Expand Down
17 changes: 17 additions & 0 deletions test/scripts/helpers/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ describe('open_graph', function() {
result.should.contain(meta({property: 'og:image', content: hexo.config.url + '/test.jpg'}));
});

it('images - resolve relative path when site is hosted in subdirectory', function() {
var urlFn = require('url');
var config = hexo.config;
config.url = urlFn.resolve(config.url, 'blog');
config.root = 'blog';
var postUrl = urlFn.resolve(config.url, '/foo/bar/index.html');

var result = openGraph.call({
page: {},
config: config,
is_post: isPost,
url: postUrl
}, {images: 'test.jpg'});

result.should.contain(meta({property: 'og:image', content: urlFn.resolve(config.url, '/foo/bar/test.jpg')}));
});

it('site_name - options', function() {
var result = openGraph.call({
page: {},
Expand Down

0 comments on commit c927811

Please sign in to comment.