Skip to content

Commit

Permalink
🚚 Feat: migrate ~~ibruce.siteTime~~ to footer.siteTime
Browse files Browse the repository at this point in the history
*The parameter `ibruce.siteTime` is deprecated since v0.2.14, use `footer.siteTime` instead*
  • Loading branch information
Lruihao committed Apr 28, 2022
1 parent cae2f87 commit 66847cf
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ All notable changes to this project will be documented in this file.
- :sparkles: Feat: add "Edit this page" button support ([#103](https://github.com/Lruihao/FixIt/issues/103))
- :sparkles: Feat: add count badge for taxonomy ([#122](https://github.com/Lruihao/FixIt/issues/122))
- :zap: Perf: add Gravatar config support
> :warning: *The parameter `home.profile.gravatarSite` is deprecated since v0.2.14, use `params.gravatar.host` instead.*
- :bug: Fix: invalid front matter `comment: true` ([#108](https://github.com/Lruihao/FixIt/issues/108))
- :bug: Fix: ibruce and watermark option negative value error ([#114](https://github.com/Lruihao/FixIt/issues/114))
- :truck: Feat: *migrate ~~`home.profile.gravatarSite`~~ to `gravatar.host`*
- :truck: Feat: *migrate ~~`ibruce.siteTime`~~ to `footer.siteTime`*
- :lipstick: Style: add some common CSS styles Class ([#101](https://github.com/Lruihao/FixIt/issues/101))
- :lipstick: Style: add the gap between and icon and text at blending typesetting (@ctj12461, @Lruihao[#118](https://github.com/Lruihao/FixIt/pull/118))
- :lipstick: Style: modify blockquote CSS
Expand Down
2 changes: 1 addition & 1 deletion assets/css/_partial/_footer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ footer {
.footer-line {
width: 100%;

.footer-divider::before {
.footer-divider:not(:first-child)::before {
content: '|';
margin-left: 0.25rem;
margin-right: 0.25rem;
Expand Down
2 changes: 1 addition & 1 deletion assets/js/theme.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/theme.min.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ enableEmoji = true
# site creation time
# 网站创立年份
since = 2021
# Site creation time since v0.2.14
# 网站创立时间 since v0.2.14
siteTime = '2021-12-18T16:15:22+08:00'
# Public network security only in China (HTML format is supported) since v0.2.12
# 公网安备信息,仅在中国使用 (支持 HTML 格式) since v0.2.12
gov = ""
Expand Down Expand Up @@ -1012,9 +1015,6 @@ enableEmoji = true
# Enable in post meta
# 在文章中开启
enablePost = true
# Site creation time
# 网站创立时间
siteTime = '2021-12-18T16:15:22+08:00'

# Site verification code for Google/Bing/Yandex/Pinterest/Baidu/360/Sogou
# 网站验证代码,用于 Google/Bing/Yandex/Pinterest/Baidu/360/Sogou
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ Please open the code block below to view the complete sample configuration :(far
author = true
# Site creation time
since = 2019
# {{< version 0.2.14 >}} Site creation time
siteTime = '' # e.g. '2019-02-03T19:30:34+08:00'
# ICP info only in China (HTML format is supported)
icp = ""
# license info (HTML format is supported)
Expand Down Expand Up @@ -714,8 +716,9 @@ Please open the code block below to view the complete sample configuration :(far
enable = true
# Enable in post meta
enablePost = false
# Site creation time e.g. '2019-02-03T19:30:34+08:00'
siteTime = ''
# {{< version 0.2.14 changed >}} {{< version 0.2.15 deleted >}} Site creation time
# The parameter `ibruce.siteTime` is deprecated since v0.2.14, use `footer.siteTime` instead
siteTime = '' # e.g. '2019-02-03T19:30:34+08:00'

# Site verification code config for Google/Bing/Yandex/Pinterest/Baidu/360/Sogou
[params.verification]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ hugo
author = true
# 网站创立年份
since = 2019
# {{< version 0.2.14 >}} 网站创立时间
siteTime = '' # 例:'2019-02-03T19:30:34+08:00'
# {{< version 0.2.12 >}} 公网安备信息,仅在中国使用(支持 HTML 格式)
gov = ""
# {{< version 0.2.12 changed >}} ICP 备案信息,仅在中国使用(支持 HTML 格式)
Expand Down Expand Up @@ -724,9 +726,9 @@ hugo
enable = true
# 在文章中开启
enablePost = false
# 网站创立时间 例:'2019-02-03T19:30:34+08:00'
siteTime = ''

# {{< version 0.2.14 changed >}} {{< version 0.2.15 deleted >}} 网站创立时间
# 参数 `ibruce.siteTime` 自 v0.2.14 起已弃用,请改用 `footer.siteTime`
# siteTime = '' # 例:'2019-02-03T19:30:34+08:00'
# 网站验证代码,用于 Google/Bing/Yandex/Pinterest/Baidu/360/Sogou
[params.verification]
google = ""
Expand Down Expand Up @@ -1103,8 +1105,8 @@ Hugo 有一个简单而强大的 [菜单系统](https://gohugo.io/content-manage

例如:

- [有草稿菜单的预览环境](https://pre.fixit.lruihao.cn)
- [没有草稿菜单的生产环境](https://fixit.lruihao.cn)
- [有草稿菜单的预览环境](https://pre.fixit.lruihao.cn/zh-cn/)
- [没有草稿菜单的生产环境](https://fixit.lruihao.cn/zh-cn/)
{{< /admonition >}}

#### 3.4.3 添加内容到菜单 {#content-to-menu}
Expand Down
8 changes: 6 additions & 2 deletions layouts/partials/assets.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,12 @@
{{- if eq .Site.Params.ibruce.enable true -}}
{{- $source := "//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" -}}
{{- dict "Source" $source "Fingerprint" $fingerprint "Async" true "Defer" true | dict "Scratch" .Scratch "Data" | partial "scratch/script.html" -}}
{{- $ibruceConfig := dict "enable" true "siteTime" .Site.Params.ibruce.siteTime -}}
{{- $config = dict "ibruce" $ibruceConfig | merge $config -}}
{{- end -}}

{{- /* Site creation time */ -}}
{{- /* TODO: The parameter `ibruce.siteTime` will be deleted in v0.2.15 */ -}}
{{- if .Site.Params.ibruce.siteTime | or .Site.Params.footer.siteTime -}}
{{- $config = dict "siteTime" (.Site.Params.ibruce.siteTime | default .Site.Params.footer.siteTime) | merge $config -}}
{{- end -}}

{{- /* PWA */ -}}
Expand Down
10 changes: 7 additions & 3 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,17 @@
</div>
{{- end -}}

<div class="footer-line statistics">
{{- /* TODO: The parameter `ibruce.siteTime` will be deleted in v0.2.15 */ -}}
{{- if .Site.Params.ibruce.siteTime | or .Site.Params.footer.siteTime -}}
<span class="site-time" title={{ T "siteRunning" }}><i class="fas fa-heartbeat fa-fw animate-icon"></i>&nbsp;<span class="run-times">Loading ...</span></span>
{{- end -}}
</div>

{{- /* 不蒜子 */ -}}
{{- if eq .Site.Params.ibruce.enable true -}}
<div class="footer-line ibruce">
<span id="busuanzi_container_site_uv" title={{ T "siteUV" }}><i class="far fa-user fa-fw"></i><span id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin fa-fw"></i></span></span>
{{- if .Site.Params.ibruce.siteTime -}}
<span class="site-time footer-divider" title={{ T "siteRunning" }}><i class="fas fa-heartbeat fa-fw animate-icon"></i>&nbsp;<span class="run-times">Loading...</span></span>
{{- end -}}
<span id="busuanzi_container_site_pv" class="footer-divider" title={{ T "sitePV" }}><i class="far fa-eye fa-fw"></i>&nbsp;<span id="busuanzi_value_site_pv"><i class="fa fa-spinner fa-spin fa-fw"></i></span></span>
</div>
{{- end -}}
Expand Down
9 changes: 8 additions & 1 deletion layouts/partials/init.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@
{{- end -}}

{{- /* Deprecated parameter detection */ -}}
{{- $warnErrors := slice -}}
{{- with .Site.Params.home.profile.gravatarSite -}}
{{- warnf "%v" "The parameter `home.profile.gravatarSite` is deprecated since v0.2.14, use `params.gravatar.host` instead." -}}
{{- $warnErrors = $warnErrors | append "The parameter `home.profile.gravatarSite` is deprecated since v0.2.14, use `gravatar.host` instead." -}}
{{- end -}}
{{- with .Site.Params.ibruce.siteTime -}}
{{- $warnErrors = $warnErrors | append "The parameter `ibruce.siteTime` is deprecated since v0.2.14, use `footer.siteTime` instead." -}}
{{- end -}}
{{- if len $warnErrors -}}
{{- warnf "Deprecated parameter detection until %v\n - %v" $version (delimit $warnErrors "\n - ") -}}
{{- end -}}

{{- .Scratch.Set "version" $version -}}
Expand Down
25 changes: 19 additions & 6 deletions src/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class Util {
};
!reserved && element.addEventListener('animationend', handler, false);
}

/**
* date validator
* @param {*} date may be date or not
* @returns {Boolean}
*/
isValidDate(date) {
return date instanceof Date && !isNaN(date.getTime());
}
}

class Theme {
Expand Down Expand Up @@ -790,21 +799,25 @@ class Theme {
this.config.cookieconsent && cookieconsent.initialise(this.config.cookieconsent);
}

getSiteTime() {
getSiteTime = () => {
let now = new Date();
let run = new Date(this.config.ibruce.siteTime);
let run = new Date(this.config.siteTime);
let $siteTime = document.querySelector('.site-time');
if (!this.util.isValidDate(run) || !$siteTime) {
clearInterval(this.siteTime);
$siteTime && $siteTime.remove();
return;
}
let runTime = (now - run) / 1000,
days = Math.floor(runTime / 60 / 60 / 24),
hours = Math.floor(runTime / 60 / 60 - 24 * days),
minutes = Math.floor(runTime / 60 - 24 * 60 * days - 60 * hours),
seconds = Math.floor((now - run) / 1000 - 24 * 60 * 60 * days - 60 * 60 * hours - 60 * minutes);
document.querySelector('.run-times').innerHTML = `${days},${String(hours).padStart(2, 0)}:${String(minutes).padStart(2, 0)}:${String(
seconds
).padStart(2, 0)}`;
$siteTime.querySelector('.run-times').innerHTML = `${days}, ${String(hours).padStart(2, 0)}:${String(minutes).padStart(2, 0)}:${String(seconds).padStart(2, 0)}`;
}

initSiteTime() {
if (this.config?.ibruce?.enable && this.config?.ibruce?.siteTime) {
if (this.config.siteTime) {
this.siteTime = setInterval(this.getSiteTime, 500);
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
Expand Down

0 comments on commit 66847cf

Please sign in to comment.