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

48 lines
1.7 KiB
React
Raw Normal View History

2019-12-22 22:23:49 +00:00
'use strict';
const { URL } = require('url');
const { Component } = require('inferno');
const { cacheComponent } = require('../util/cache');
class Links extends Component {
render() {
const { title, links } = this.props;
return <div className="card widget">
<div className="card-content">
<div className="menu">
<h3 className="menu-label">{title}</h3>
<ul className="menu-list">
2019-12-22 22:23:49 +00:00
{Object.keys(links).map(i => {
let hostname = links[i];
try {
hostname = new URL(hostname).hostname;
} catch (e) { }
return <li>
<a className="level is-mobile" href="<%- links[i] %>" target="_blank" rel="noopener">
<span className="level-left">
<span className="level-item">{i}</span>
2019-12-22 22:23:49 +00:00
</span>
<span className="level-right">
<span className="level-item tag">{hostname}</span>
2019-12-22 22:23:49 +00:00
</span>
</a>
</li>;
})}
</ul>
</div>
</div>
</div>;
}
}
module.exports = cacheComponent(Links, 'widget.links', props => {
const { helper, widget } = props;
if (!Object.keys(widget.links).length) {
2019-12-22 22:23:49 +00:00
return null;
}
return {
title: helper.__('widget.links'),
links: widget.links
2019-12-22 22:23:49 +00:00
};
});