Skip to content

Commit

Permalink
Merge pull request #3701 from SukkaW/full_url_for
Browse files Browse the repository at this point in the history
feat(full_url_for): utilize hexo-util module
  • Loading branch information
curbengh authored Sep 17, 2019
2 parents 55dc487 + bfd8b0a commit 19ac152
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/plugins/helper/full_url_for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';
const { full_url_for } = require('hexo-util');

module.exports = function(path) {
return full_url_for.call(this, path);
};
1 change: 1 addition & 0 deletions lib/plugins/helper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module.exports = ctx => {

helper.register('relative_url', require('./relative_url'));
helper.register('url_for', require('./url_for'));
helper.register('full_url_for', require('./full_url_for'));

const debug = require('./debug');
helper.register('inspect', debug.inspectObject);
Expand Down
32 changes: 32 additions & 0 deletions test/scripts/helpers/full_url_for.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

describe('full_url_for', () => {
const ctx = {
config: { url: 'https://example.com' }
};

const fullUrlFor = require('../../../lib/plugins/helper/full_url_for').bind(ctx);

it('no path input', () => {
fullUrlFor().should.eql(ctx.config.url + '/');
});

it('internal url', () => {
fullUrlFor('index.html').should.eql(ctx.config.url + '/index.html');
fullUrlFor('/').should.eql(ctx.config.url + '/');
fullUrlFor('/index.html').should.eql(ctx.config.url + '/index.html');
});

it('external url', () => {
[
'https://hexo.io/',
'//google.com/'
].forEach(url => {
fullUrlFor(url).should.eql(url);
});
});

it('only hash', () => {
fullUrlFor('#test').should.eql(ctx.config.url + '/#test');
});
});
1 change: 1 addition & 0 deletions test/scripts/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('Helpers', () => {
require('./favicon_tag');
require('./feed_tag');
require('./fragment_cache');
require('./full_url_for');
require('./gravatar');
require('./image_tag');
require('./is');
Expand Down

0 comments on commit 19ac152

Please sign in to comment.