hexo-theme-amane/layout/widget/tags.jsx

63 lines
1.7 KiB
React
Raw Normal View History

2019-12-22 22:23:49 +00:00
'use strict';
const { Component } = require('inferno');
const { cacheComponent } = require('../util/cache');
class Tags extends Component {
render() {
const {
tags,
title,
showCount
} = this.props;
return <div className="card widget">
<div className="card-content">
<div className="menu">
<h3 className="menu-label">{title}</h3>
<div className="field is-grouped is-grouped-multiline">
{tags.map(tag => <div className="control">
<a className="tags has-addons" href={tag.url}>
<span className="tag">{tag.name}</span>
{showCount ? <span className="tag is-grey">{tag.count}</span> : null}
2019-12-22 22:23:49 +00:00
</a>
</div>)}
</div>
</div>
</div>
</div>;
}
}
module.exports = cacheComponent(Tags, 'widget.tags', props => {
// adapted from hexo/lib/plugins/helper/list_tags.js
const {
helper,
orderBy = 'name',
order = 1,
amount,
show_count = true
} = props;
2019-12-22 22:23:49 +00:00
let tags = props.tags || props.site.tags;
const { url_for, _p } = helper;
if (!tags || !tags.length) {
2019-12-22 22:23:49 +00:00
return null;
}
tags = tags.sort(orderBy, order).filter(tag => tag.length);
if (amount) {
tags = tags.limit(amount);
}
return {
showCount: show_count,
2019-12-22 22:23:49 +00:00
title: _p('common.tag', Infinity),
tags: tags.map(tag => ({
name: tag.name,
count: tag.length,
url: url_for(tag.path)
}))
};
});