2019-12-22 22:23:49 +00:00
|
|
|
const { Component } = require('inferno');
|
|
|
|
const gravatrHelper = require('hexo-util').gravatar;
|
|
|
|
const { cacheComponent } = require('../util/cache');
|
|
|
|
|
|
|
|
class Profile extends Component {
|
|
|
|
renderSocialLinks(links) {
|
|
|
|
if (!links.length) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-12-24 05:36:39 +00:00
|
|
|
return <div class="level is-mobile">
|
2019-12-25 05:35:34 +00:00
|
|
|
{links.filter(link => typeof link === 'object').map(link => {
|
2019-12-24 05:36:39 +00:00
|
|
|
return <a class="level-item button is-white is-marginless"
|
2019-12-22 22:23:49 +00:00
|
|
|
target="_blank" rel="noopener" title={link.name} href={link.url}>
|
2019-12-24 05:36:39 +00:00
|
|
|
{'icon' in link ? <i class={link.icon}></i> : link.name}
|
2019-12-22 22:23:49 +00:00
|
|
|
</a>;
|
|
|
|
})}
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
avatar,
|
|
|
|
avatarRounded,
|
|
|
|
author,
|
|
|
|
authorTitle,
|
|
|
|
location,
|
|
|
|
counter,
|
|
|
|
followLink,
|
|
|
|
followTitle,
|
|
|
|
socialLinks
|
|
|
|
} = this.props;
|
2019-12-24 05:36:39 +00:00
|
|
|
return <div class="card widget">
|
|
|
|
<div class="card-content">
|
|
|
|
<nav class="level">
|
|
|
|
<div class="level-item has-text-centered" style="flex-shrink: 1">
|
2019-12-22 22:23:49 +00:00
|
|
|
<div>
|
2019-12-24 05:36:39 +00:00
|
|
|
<figure class="image is-128x128 has-mb-6">
|
|
|
|
<img class={avatarRounded ? 'is-rounded' : ''} src={avatar} alt={author} />
|
2019-12-22 22:23:49 +00:00
|
|
|
</figure>
|
2019-12-24 05:36:39 +00:00
|
|
|
{author ? <p class="is-size-4 is-block">{author}</p> : null}
|
|
|
|
{authorTitle ? <p class="is-size-6 is-block">{authorTitle}</p> : null}
|
|
|
|
{location ? <p class="is-size-6 is-flex is-flex-center has-text-grey">
|
|
|
|
<i class="fas fa-map-marker-alt has-mr-7"></i>
|
2019-12-22 22:23:49 +00:00
|
|
|
<span>{location}</span>
|
|
|
|
</p> : null}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2019-12-24 05:36:39 +00:00
|
|
|
<nav class="level is-mobile">
|
|
|
|
<div class="level-item has-text-centered is-marginless">
|
2019-12-22 22:23:49 +00:00
|
|
|
<div>
|
2019-12-24 05:36:39 +00:00
|
|
|
<p class="heading">{counter.post.title}</p>
|
2019-12-22 22:23:49 +00:00
|
|
|
<a href={counter.post.url}>
|
2019-12-24 05:36:39 +00:00
|
|
|
<p class="title has-text-weight-normal">{counter.post.count}</p>
|
2019-12-22 22:23:49 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-24 05:36:39 +00:00
|
|
|
<div class="level-item has-text-centered is-marginless">
|
2019-12-22 22:23:49 +00:00
|
|
|
<div>
|
2019-12-24 05:36:39 +00:00
|
|
|
<p class="heading">{counter.category.title}</p>
|
2019-12-22 22:23:49 +00:00
|
|
|
<a href={counter.category.url}>
|
2019-12-24 05:36:39 +00:00
|
|
|
<p class="title has-text-weight-normal">{counter.category.count}</p>
|
2019-12-22 22:23:49 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-12-24 05:36:39 +00:00
|
|
|
<div class="level-item has-text-centered is-marginless">
|
2019-12-22 22:23:49 +00:00
|
|
|
<div>
|
2019-12-24 05:36:39 +00:00
|
|
|
<p class="heading">{counter.tag.title}</p>
|
2019-12-22 22:23:49 +00:00
|
|
|
<a href={counter.tag.url}>
|
2019-12-24 05:36:39 +00:00
|
|
|
<p class="title has-text-weight-normal">{counter.tag.count}</p>
|
2019-12-22 22:23:49 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</nav>
|
2019-12-24 05:36:39 +00:00
|
|
|
{followLink ? <div class="level">
|
|
|
|
<a class="level-item button is-link is-rounded" href={followLink} target="_blank" rel="noopener">{followTitle}</a>
|
2019-12-22 22:23:49 +00:00
|
|
|
</div> : null}
|
|
|
|
{this.renderSocialLinks(socialLinks)}
|
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = cacheComponent(Profile, 'widget.profile', props => {
|
2019-12-23 06:49:48 +00:00
|
|
|
const { site, helper, widget } = props;
|
2019-12-22 22:23:49 +00:00
|
|
|
const {
|
|
|
|
avatar,
|
|
|
|
gravatar,
|
|
|
|
avatar_rounded = false,
|
|
|
|
author = props.config.author,
|
|
|
|
author_title,
|
|
|
|
location,
|
|
|
|
follow_link,
|
2019-12-23 06:49:48 +00:00
|
|
|
social_links
|
|
|
|
} = widget;
|
|
|
|
const { url_for, _p, __ } = helper;
|
2019-12-22 22:23:49 +00:00
|
|
|
|
|
|
|
function getAvatar() {
|
|
|
|
if (gravatar) {
|
|
|
|
return gravatrHelper(gravatar, 128);
|
|
|
|
}
|
|
|
|
if (avatar) {
|
|
|
|
return url_for(avatar);
|
|
|
|
}
|
2019-12-25 01:34:27 +00:00
|
|
|
return url_for('/img/avatar.png');
|
2019-12-22 22:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.name),
|
|
|
|
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
|
|
|
|
};
|
|
|
|
});
|