Skip to content

Commit

Permalink
add notice widget
Browse files Browse the repository at this point in the history
  • Loading branch information
removeif committed May 22, 2020
1 parent 179319a commit a5d8df2
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 0 deletions.
7 changes: 7 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,13 @@ widgets:
# client_id: ''
# # AdSense AD unit ID
# slot_id: ''
-
# position: right
# type: notice
# contents:
# 1: 2019.8.15 <a href="https://github.com/removeif/hexo-theme-amazing" target="_blank">主题开源</a>
# 2: 2020.5.20 添加公告widget
# 3: 2020.5.21 公告测试
# Plugin configurations
plugins:
# Enable page startup animations
Expand Down
3 changes: 3 additions & 0 deletions include/schema/common/widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
},
{
"$ref": "/widget/adsense.json"
},
{
"$ref": "/widget/notice.json"
}
],
"required": [
Expand Down
31 changes: 31 additions & 0 deletions include/schema/widget/notice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "/widget/notice.json",
"description": "Notice links widget configurations",
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "notice"
},
"contents": {
"type": "object",
"description": "notic contents",
"patternProperties": {
".+": {
"type": "string",
"description": "URL of the site"
}
},
"examples": [
{
"1": "2019.05.23 建站"
}
],
"nullable": true
}
},
"required": [
"type"
]
}
1 change: 1 addition & 0 deletions languages/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ widget:
hot_recommend_tip: 'Loading...Wait a Minute!'
hitokoto_from: 'From'
hitokoto_provider: 'Provider'
notice: 'Notice'

article:
more: 'Read More'
Expand Down
1 change: 1 addition & 0 deletions languages/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ widget:
hot_recommend_tip: '加载中,请稍等...'
hitokoto_from: '来源'
hitokoto_provider: '提供者'
notice: '通知'
article:
more: '阅读更多'
comments: '评论'
Expand Down
36 changes: 36 additions & 0 deletions layout/widget/notice.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const { URL } = require('url');
const { Component } = require('inferno');
const { cacheComponent } = require('../util/cache');

class Links extends Component {
render() {
const { title, contents } = this.props;
return <div class="card widget">
<div class="card-content">
<div class="menu">
<h3 class="menu-label">{title}</h3>
<ul>
{Object.keys(contents).map(key => {
return <li>
<span>
<span dangerouslySetInnerHTML={{ __html: contents[key] }}></span>
</span>
</li>;
})}
</ul>
</div>
</div>
</div>;
}
}

module.exports = cacheComponent(Links, 'widget.links', props => {
const { helper, widget } = props;
if (!Object.keys(widget.contents).length) {
return null;
}
return {
title: helper.__('widget.notice'),
contents: widget.contents
};
});

0 comments on commit a5d8df2

Please sign in to comment.