此文章使用365Blog 2.0引擎的旧版格式编写,可能未兼容新站点,部分内容可能显示异常,请谅解。

相信经常关注我博客的小伙伴一定发现我的博客下面多了这么一个东西:

notion image

下面我将教你们如何在Gridea上添加像这样的运行时间显示。

一,在全站底部添加JS代码

在资源管理器中定位到footer.ejs,在<%- themeConfig.footerInfo %>后面换行并添加:

<br>
  <div id="sitegotimeDate">运行时间载入中...</div>
  <div id="sitegotimes"></div>
  <div id="cussitetime" style="display:none"><%= site.customConfig['sitegotime'] %></div>

</footer>之后换行并添加以下内容

<script>
//----------------------站点运行时间----------------------
var now = new Date();

function createtime() {
    var sitegotime = document.getElementById("cussitetime").innerHTML + " 00:00:00";
    var grt = new Date(sitegotime); 
    now.setTime(now.getTime() + 250);
    days = (now - grt) / 1000 / 60 / 60 / 24;
    dnum = Math.floor(days);
    hours = (now - grt) / 1000 / 60 / 60 - (24 * dnum);
    hnum = Math.floor(hours);
    if (String(hnum).length == 1) {
        hnum = "0" + hnum;
    }
    minutes = (now - grt) / 1000 / 60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes);
    if (String(mnum).length == 1) {
        mnum = "0" + mnum;
    }
    seconds = (now - grt) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds);
    if (String(snum).length == 1) {
        snum = "0" + snum;
    }
    document.getElementById("sitegotimeDate").innerHTML = "目前站点已经运行了" + dnum + " 天 ";
    document.getElementById("sitegotimes").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}

let intervalId = setInterval("createtime()", 250);
</script>

即可。

二,添加配置项

资源管理器定位到config.json配置文件,在最后面或最前面添加以下内容:

{
      "name": "sitegotimeChoice",
      "label": "是否开启站点创建时间",
      "group": "统计",
      "value": false,
      "type": "switch",
      "note": ""
    },
    {
      "name": "sitegotime",
      "label": "站点创建时间",
      "group": "统计",
      "value": "02/22/2020",
      "type": "input",
      "note": "输入日期(格式:02/22/2020)"
    },

打开Gridea(若之前修改时已经打开则重启Gridea),选择Theme,再选择Custom configuration,点击统计,配置完成即可。