From 51e291c61519224c3d9ff62cc2850fe3eb78f60c Mon Sep 17 00:00:00 2001 From: ppoffice Date: Sun, 23 Dec 2018 13:53:18 -0500 Subject: [PATCH] chore(widget): show domain name instead of full url in links widget --- includes/helpers/site.js | 7 +++++++ layout/widget/links.ejs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/includes/helpers/site.js b/includes/helpers/site.js index ef50a0d..08cd226 100644 --- a/includes/helpers/site.js +++ b/includes/helpers/site.js @@ -3,12 +3,14 @@ * * @example * <%- is_same_link(url_a, url_b) %> +* <%- get_domain(url) %> * <%- post_count() %> * <%- category_count() %> * <%- tag_count() %> * <%- duration() %> * <%- word_count(content) %> */ +const URL = require('url').URL; const moment = require('moment'); module.exports = function (hexo) { @@ -23,6 +25,11 @@ module.exports = function (hexo) { return santize(this.url_for(a)) == santize(this.url_for(b)); }); + hexo.extend.helper.register('get_domain', function (link) { + const url = new URL(link); + return url.hostname; + }); + hexo.extend.helper.register('post_count', function () { return this.site.posts.length; }); diff --git a/layout/widget/links.ejs b/layout/widget/links.ejs index c87c605..2a1e629 100644 --- a/layout/widget/links.ejs +++ b/layout/widget/links.ejs @@ -14,7 +14,7 @@ <%= i %> - <%- links[i] %> + <%- get_domain(links[i]) %>