chore(widget): show domain name instead of full url in links widget

This commit is contained in:
ppoffice 2018-12-23 13:53:18 -05:00
parent 90414e8062
commit 51e291c615
2 changed files with 8 additions and 1 deletions

View File

@ -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;
});

View File

@ -14,7 +14,7 @@
<span class="level-item"><%= i %></span>
</span>
<span class="level-right">
<span class="level-item tag"><%- links[i] %></span>
<span class="level-item tag"><%- get_domain(links[i]) %></span>
</span>
</a>
</li>