const { Component } = require('inferno'); const gravatrHelper = require('hexo-util').gravatar; const { cacheComponent } = require('hexo-component-inferno/lib/util/cache'); class Profile extends Component { renderSocialLinks(links) { if (!links.length) { return null; } return
{links.filter(link => typeof link === 'object').map(link => { return {'icon' in link ? : link.name} ; })}
; } render() { const { avatar, avatarRounded, author, authorTitle, location, counter, followLink, followTitle, socialLinks } = this.props; return
{followLink ? : null} {this.renderSocialLinks(socialLinks)}
; } } Profile.Cacheable = cacheComponent(Profile, 'widget.profile', props => { const { site, helper, widget } = props; const { avatar, gravatar, avatar_rounded = false, author = props.config.author, author_title, location, follow_link, social_links } = widget; const { url_for, _p, __ } = helper; function getAvatar() { if (gravatar) { return gravatrHelper(gravatar, 128); } if (avatar) { return url_for(avatar); } return url_for('/img/avatar.png'); } const postCount = site.posts.length; const categoryCount = site.categories.filter(category => category.length).length; const tagCount = site.tags.filter(tag => tag.length).length; const socialLinks = Object.keys(social_links).map(name => { const link = social_links[name]; if (typeof link === 'string') { return { name, url: url_for(link) }; } return { name, url: url_for(link.url), icon: link.icon }; }); return { avatar: getAvatar(), avatarRounded: avatar_rounded, author, authorTitle: author_title, location, counter: { post: { count: postCount, title: _p('common.post', postCount), url: url_for('/archives') }, category: { count: categoryCount, title: _p('common.category', categoryCount), url: url_for('/categories') }, tag: { count: tagCount, title: _p('common.tag', tagCount), url: url_for('/tags') } }, followLink: url_for(follow_link), followTitle: __('widget.follow'), socialLinks }; }); module.exports = Profile;