mirror of https://gitlab.com/curben/blog
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:
parent
36201c2ada
commit
aa3d94aa4b
|
@ -10,6 +10,6 @@
|
||||||
<hr>
|
<hr>
|
||||||
<% } %>
|
<% } %>
|
||||||
<div id="copyright" class="copyright">
|
<div id="copyright" class="copyright">
|
||||||
© 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') %>
|
© 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>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue