add widget "server-status"

This commit is contained in:
TaurusXin 2021-12-16 14:10:35 +00:00
parent 1919be2d48
commit 4ce38d51a7
4 changed files with 71 additions and 1 deletions

7
assets/icons/status.svg Normal file
View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-server" width="100" height="100" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
<rect x="3" y="4" width="18" height="8" rx="3" />
<rect x="3" y="12" width="18" height="8" rx="3" />
<line x1="7" y1="8" x2="7" y2="8.01" />
<line x1="7" y1="16" x2="7" y2="16.01" />
</svg>

After

Width:  |  Height:  |  Size: 479 B

View File

@ -139,6 +139,7 @@ params:
- search - search
- tag-cloud - tag-cloud
- archives - archives
- status
categoriesCloud: categoriesCloud:
limit: 20 limit: 20
@ -148,6 +149,10 @@ params:
tagCloud: tagCloud:
limit: 10 limit: 10
status:
start: 2018-08-04
format: yyyy 年 MM 月 dd 日
opengraph: opengraph:
twitter: twitter:

View File

@ -1,4 +1,10 @@
widget: widget:
categoriesCloud: categoriesCloud:
title: title:
other: 分类 other: 分类
status:
title: 状态
start: 博客建立自:
time: 已稳定运行:
postCount: 总文章数量:

View File

@ -0,0 +1,52 @@
{{/*-- post count */}}
{{ $posts := (where .Site.RegularPages "Section" "==" "post") }}
{{ $postCount := len $posts }}
<section class="widget tagCloud">
<div class="widget-icon">
{{ partial "helper/icon" "status" }}
</div>
<h2 class="widget-title section-title">{{ T "widget.status.title" }}</h2>
<div class="tagCloud-tags" style="display: flex; flex-direction: column;">
<div style="padding: 10px 0; color: #bababa;">{{ T "widget.status.postCount" }}{{ $postCount }}</div>
<div style="padding: 10px 0; color: #bababa;">{{ T "widget.status.start" }}<span id="start"></span></div>
<div style="padding: 10px 0; color: #bababa;">{{ T "widget.status.time" }}<span id="time"></span></div>
</div>
<script>
Date.prototype.format = function(fmt) {
var o = {
"M+" : this.getMonth()+1, //月份
"d+" : this.getDate(), //日
"h+" : this.getHours(), //小时
"m+" : this.getMinutes(), //分
"s+" : this.getSeconds(), //秒
"q+" : Math.floor((this.getMonth()+3)/3), //季度
"S" : this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) {
fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
}
for(var k in o) {
if(new RegExp("("+ k +")").test(fmt)){
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
}
}
return fmt;
}
let start = new Date({{ .Site.Params.widgets.status.start }})
let startFormated = start.format({{ .Site.Params.widgets.status.format }})
document.querySelector('#start').innerHTML = startFormated
let now = new Date()
let diff = new Date(now.getTime() - start.getTime());
let years = (diff.getUTCFullYear() - 1970)
let months = diff.getUTCMonth()
let days = diff.getUTCDate() - 1
document.querySelector('#time').innerHTML = years + ' 年 ' + months + ' 月 ' + days + ' 天'
</script>
</section>