2019-08-09 13:02:51 +00:00
|
|
|
'use strict'
|
|
|
|
/* global hexo */
|
|
|
|
|
2019-06-15 11:12:07 +00:00
|
|
|
/*
|
|
|
|
* Modified from the hexo version,
|
|
|
|
* https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/link_to.js
|
|
|
|
* to remove title attribute and 'external' option
|
|
|
|
*/
|
|
|
|
|
|
|
|
const { htmlTag } = require('hexo-util')
|
|
|
|
|
2019-08-09 13:02:51 +00:00
|
|
|
function linkHelper (path, text) {
|
2019-06-15 11:12:07 +00:00
|
|
|
if (!text) text = path.replace(/^https?:\/\/|\/$/g, '')
|
|
|
|
|
|
|
|
const attrs = Object.assign({
|
|
|
|
href: this.url_for(path)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (attrs.class && Array.isArray(attrs.class)) {
|
|
|
|
attrs.class = attrs.class.join(' ')
|
|
|
|
}
|
|
|
|
|
|
|
|
return htmlTag('a', attrs, text)
|
|
|
|
}
|
|
|
|
|
|
|
|
hexo.extend.helper.register('link', linkHelper)
|