From aa3d94aa4b6126a2ccc6ee357df58c0533069e52 Mon Sep 17 00:00:00 2001 From: curben Date: Sat, 15 Jun 2019 20:42:07 +0930 Subject: [PATCH] feat: add link() helper * Based on link_to() helper, without unneeded attribute and option * https://hexo.io/docs/helpers#link-to --- themes/typing/layout/_partial/footer.ejs | 2 +- themes/typing/scripts/link.js | 25 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 themes/typing/scripts/link.js diff --git a/themes/typing/layout/_partial/footer.ejs b/themes/typing/layout/_partial/footer.ejs index c292b2f..9966ca8 100644 --- a/themes/typing/layout/_partial/footer.ejs +++ b/themes/typing/layout/_partial/footer.ejs @@ -10,6 +10,6 @@
<% } %> diff --git a/themes/typing/scripts/link.js b/themes/typing/scripts/link.js new file mode 100644 index 0000000..bd42e9f --- /dev/null +++ b/themes/typing/scripts/link.js @@ -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)