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

refactor: deprecate config.external_link as boolean #4376

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
17 changes: 9 additions & 8 deletions lib/plugins/filter/after_post_render/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ function externalLinkFilter(data) {
const { config } = this;

if (typeof EXTERNAL_LINK_POST_CONFIG === 'undefined') {
if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object'
// Deprecated: config.external_link boolean option will be removed in future
|| config.external_link === true) {
EXTERNAL_LINK_POST_CONFIG = Object.assign({
enable: true,
field: 'site',
exclude: []
}, config.external_link);
// Deprecated: config.external_link no longer support boolean
if (typeof config.external_link === 'boolean') {
throw new TypeError('config.external_link no longer supports Boolean value, changelog: https://github.com/hexojs/hexo/releases/');
Copy link
Contributor

@curbengh curbengh Jun 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would better to retain support for now but display a warning, so that the breaking change is not so sudden.
Since it will deprecated in v5, it's clearer to link directly to https://github.com/hexojs/hexo/releases/tag/5.0.0
Usage of config.use_date_for_updated should also display warning.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already deprecate it in Hexo 4.0.0. So it is fine when we remove it in Hexo 5.0.0.

I will open another PR to add a warning for use_date_for_updated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already deprecate it in Hexo 4.0.0.

That was the initial intention, however we forgot to mention it in the v4 release note. Can we soft-deprecate it this time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@curbengh IMHO we could bring up a config validation.

}

EXTERNAL_LINK_POST_CONFIG = Object.assign({
enable: true,
field: 'site',
exclude: []
}, config.external_link);
}

if (config.external_link === false || EXTERNAL_LINK_POST_CONFIG.enable === false
Expand Down
17 changes: 9 additions & 8 deletions lib/plugins/filter/after_render/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ function externalLinkFilter(data) {
const { config } = this;

if (typeof EXTERNAL_LINK_SITE_CONFIG === 'undefined') {
if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object'
// Deprecated: config.external_link boolean option will be removed in future
|| config.external_link === true) {
EXTERNAL_LINK_SITE_CONFIG = Object.assign({
enable: true,
field: 'site',
exclude: []
}, config.external_link);
// Deprecated: config.external_link no longer support boolean
if (typeof config.external_link === 'boolean') {
throw new TypeError('config.external_link no longer supports Boolean value, changelog: https://github.com/hexojs/hexo/releases/');
}

EXTERNAL_LINK_SITE_CONFIG = Object.assign({
enable: true,
field: 'site',
exclude: []
}, config.external_link);
}

if (config.external_link === false || EXTERNAL_LINK_SITE_CONFIG.enable === false
Expand Down
31 changes: 22 additions & 9 deletions test/scripts/filters/external_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,20 @@ describe('External link', () => {
].join('\n'));
});

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

hexo.config.external_link = false;

should.not.exist(externalLink(content));
try {
externalLink(content);
} catch (err) {
err.name.should.eql('TypeError');
err.message.should.eql('config.external_link no longer supports Boolean value, changelog: https://github.com/hexojs/hexo/releases/');
}

hexo.config.external_link = {
enable: true,
field: 'site',
Expand All @@ -115,8 +121,12 @@ describe('External link', () => {

hexo.config.external_link = true;

const result = externalLink(content);
result.should.eql('<a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>');
try {
externalLink(content);
} catch (err) {
err.name.should.eql('TypeError');
err.message.should.eql('config.external_link no longer supports Boolean value, changelog: https://github.com/hexojs/hexo/releases/');
}

hexo.config.external_link = {
enable: true,
Expand Down Expand Up @@ -271,17 +281,20 @@ describe('External link - post', () => {
].join('\n'));
});


it('backward compatibility', () => {
it('deprecated boolean config', () => {
const content = 'foo'
+ '<a href="https://hexo.io/">Hexo</a>'
+ 'bar';

const data = {content};
const data = { content };
hexo.config.external_link = false;

externalLink(data);
data.content.should.eql(content);
try {
externalLink(data);
} catch (err) {
err.name.should.eql('TypeError');
err.message.should.eql('config.external_link no longer supports Boolean value, changelog: https://github.com/hexojs/hexo/releases/');
}

hexo.config.external_link = {
enable: true,
Expand Down