chore(copyright): 2024
[curben-blog.git] / themes / chameleon / scripts / link.js
blobf02ffb03dc1999ddafc39147e07676c652b09d6c
1 'use strict'
2 /* global hexo */
4 /*
5 * Modified from the hexo version,
6 * https://github.com/hexojs/hexo/blob/master/lib/plugins/helper/link_to.js
7 * to remove title attribute and 'external' option
8 */
10 const { htmlTag } = require('hexo-util')
12 hexo.extend.helper.register('link', (path, text) => {
13   const urlFor = hexo.extend.helper.get('url_for').bind(hexo)
15   if (!text) text = path.replace(/^https?:\/\/|\/$/g, '')
17   const attrs = Object.assign({
18     href: urlFor(path)
19   })
21   if (attrs.class && Array.isArray(attrs.class)) {
22     attrs.class = attrs.class.join(' ')
23   }
25   return htmlTag('a', attrs, text)