Skip to content

Commit

Permalink
fix(external_link): support 'external_link: true'
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Sep 24, 2019
1 parent b2df82f commit eb7b6ed
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/plugins/filter/after_post_render/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const isExternal = (url, config) => {
function externalLinkFilter(data) {
const { config } = this;

if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object') {
if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' ||
config.external_link === true) {
config.external_link = Object.assign({
enable: true,
field: 'site',
Expand Down
3 changes: 2 additions & 1 deletion lib/plugins/filter/after_render/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const isExternal = (url, config) => {
function externalLinkFilter(data) {
const { config } = this;

if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object') {
if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' ||
config.external_link === true) {
config.external_link = Object.assign({
enable: true,
field: 'site',
Expand Down
17 changes: 16 additions & 1 deletion test/scripts/filters/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('External link', () => {
].join('\n'));
});

it('backward compatibility', () => {
it('old option - false', () => {
const content = 'foo'
+ '<a href="https://hexo.io/">Hexo</a>'
+ 'bar';
Expand All @@ -107,6 +107,21 @@ describe('External link', () => {
};
});

it('old option - true', () => {
const content = '<a href="https://hexo.io/">Hexo</a>';

hexo.config.external_link = true;

const result = externalLink(content);
result.should.eql('<a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>');

hexo.config.external_link = {
enable: true,
field: 'site',
exclude: ''
};
});

it('exclude - string', () => {
const content = [
'<a href="https://foo.com/">Hexo</a>',
Expand Down

0 comments on commit eb7b6ed

Please sign in to comment.