feat: add link() helper

* Based on link_to() helper, without unneeded attribute and option
* https://hexo.io/docs/helpers#link-to
This commit is contained in:
curben 2019-06-15 20:42:07 +09:30
parent 36201c2ada
commit aa3d94aa4b
2 changed files with 26 additions and 1 deletions

View File

@ -10,6 +10,6 @@
<hr>
<% } %>
<div id="copyright" class="copyright">
&copy; 2018-<%= date(new Date(), 'YYYY') %> <%= config.author %>. <%- link_to('https://gitlab.com/curben/blog', 'Powered by ') %> <%- link_to('https://hexo.io/', 'Hexo') %> with <%- link_to('https://github.com/geekplux/hexo-theme-typing', 'Typing') %> theme. <br/>Content is available under <%- link_to('https://creativecommons.org/licenses/by-sa/4.0/', 'CC-BY-SA 4.0') %>, unless indicated otherwise. <br/><%- link_to('/disclaimer/', 'Disclaimer') %>
&copy; 2018-<%= date(new Date(), 'YYYY') %> <%= config.author %>. <%- link('https://gitlab.com/curben/blog', 'Powered by ') %> <%- link('https://hexo.io/', 'Hexo') %> with <%- link('https://github.com/geekplux/hexo-theme-typing', 'Typing') %> theme. <br/>Content is available under <%- link('https://creativecommons.org/licenses/by-sa/4.0/', 'CC-BY-SA 4.0') %>, unless indicated otherwise. <br/><%- link('/disclaimer/', 'Disclaimer') %>
</div>
</footer>

View File

@ -0,0 +1,25 @@
/*
* 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
*/
'use strict'
const { htmlTag } = require('hexo-util')
function linkHelper(path, text) {
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)