Skip to content

Commit

Permalink
style(external_link): operator-linebreak
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Oct 28, 2019
1 parent 4b90165 commit e690eca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions lib/plugins/filter/after_post_render/external_link.js
Expand Up @@ -11,8 +11,8 @@ const urlObj = (str) => {
};

const isExternal = (url, config) => {
const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude :
[config.external_link.exclude];
const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude
: [config.external_link.exclude];
const data = urlObj(url);
const host = data.hostname;
const sitehost = typeof urlObj(config.url) === 'object' ? urlObj(config.url).hostname : config.url;
Expand All @@ -34,16 +34,16 @@ const isExternal = (url, config) => {
function externalLinkFilter(data) {
const { config } = this;

if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' ||
config.external_link === true) {
if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object'
|| config.external_link === true) {
config.external_link = Object.assign({
enable: true,
field: 'site',
exclude: ''
}, config.external_link);
}
if (config.external_link === false || config.external_link.enable === false ||
config.external_link.field !== 'post') return;
if (config.external_link === false || config.external_link.enable === false
|| config.external_link.field !== 'post') return;

data.content = data.content.replace(/<a.*?(href=['"](.*?)['"]).*?>/gi, (str, hrefStr, href) => {
if (/target=/gi.test(str) || !isExternal(href, config)) return str;
Expand Down
12 changes: 6 additions & 6 deletions lib/plugins/filter/after_render/external_link.js
Expand Up @@ -17,8 +17,8 @@ const urlObj = (str) => {
* @returns {Boolean} True if the link doesn't have protocol or link has same host with config.url
*/
const isExternal = (url, config) => {
const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude :
[config.external_link.exclude];
const exclude = Array.isArray(config.external_link.exclude) ? config.external_link.exclude
: [config.external_link.exclude];
const data = urlObj(url);
const host = data.hostname;
const sitehost = typeof urlObj(config.url) === 'object' ? urlObj(config.url).hostname : config.url;
Expand All @@ -40,16 +40,16 @@ const isExternal = (url, config) => {
function externalLinkFilter(data) {
const { config } = this;

if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object' ||
config.external_link === true) {
if (typeof config.external_link === 'undefined' || typeof config.external_link === 'object'
|| config.external_link === true) {
config.external_link = Object.assign({
enable: true,
field: 'site',
exclude: ''
}, config.external_link);
}
if (config.external_link === false || config.external_link.enable === false ||
config.external_link.field !== 'site') return;
if (config.external_link === false || config.external_link.enable === false
|| config.external_link.field !== 'site') return;

data = data.replace(/<a.*?(href=['"](.*?)['"]).*?>/gi, (str, hrefStr, href) => {
if (/target=/gi.test(str) || !isExternal(href, config)) return str;
Expand Down

0 comments on commit e690eca

Please sign in to comment.