Skip to content

Commit

Permalink
Merge 91f620b into 1da7ad5
Browse files Browse the repository at this point in the history
  • Loading branch information
kflu committed Jan 9, 2017
2 parents 1da7ad5 + 91f620b commit f97fe42
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
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
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 f97fe42

Please sign in to comment.