You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
625 B
28 lines
625 B
'use strict'; |
|
|
|
const { htmlTag, url_for } = require('hexo-util'); |
|
|
|
function linkToHelper(path, text, options = {}) { |
|
if (typeof options === 'boolean') options = {external: options}; |
|
|
|
if (!text) text = path.replace(/^https?:\/\/|\/$/g, ''); |
|
|
|
const attrs = Object.assign({ |
|
href: url_for.call(this, path), |
|
title: text |
|
}, options); |
|
|
|
if (attrs.external) { |
|
attrs.target = '_blank'; |
|
attrs.rel = 'noopener'; |
|
attrs.external = null; |
|
} |
|
|
|
if (attrs.class && Array.isArray(attrs.class)) { |
|
attrs.class = attrs.class.join(' '); |
|
} |
|
|
|
return htmlTag('a', attrs, text); |
|
} |
|
|
|
module.exports = linkToHelper;
|
|
|