hexo+yilia添加网站运行时间,ICP备案信息,设定站点建立时间


hexo+yilia(在底部)添加

  • 网站运行时间:本站已安全运行 101 天 12 小时 13 分 41 秒
  • ICP备案信息:粤ICP备00000000号
  • 设定站点建立时间(年份):@ 2018 - 2019

1.添加网站运行时间

添加位置建议:如果有统计量(如不蒜子统计量),放在不蒜子后面。没有就按照下面的建议。

硬性配置

参考:Hexo主题更改以及小功能的添加–添加网站运行时间

修改\themes\yilia\layout\_partial\footer.ejs,在</footer>上面添加如下内容:

<!--《添加网站运行时间 -->
<!--<br/>-->
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
    var now = new Date();

    function createtime() {
        var grt = new Date("07/25/2019 12:00:00"); //此处修改你的建站时间或者网站上线时间 
        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("timeDate").innerHTML = " | 本站已安全运行 " + dnum + " 天 ";
        document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
    }
    setInterval("createtime()", 250);
</script>
<!-- 添加网站运行时间》 -->

灵活配置(推荐)

优化上面的内容,设置成可以直接在配置文件中进行开启和关闭的形式:

1.修改\themes\yilia\_config.yml,添加如下内容:

# 网站运行时间,格式形如:“本站已安全运行 101 天 12 小时 13 分 41 秒”
# Runing Time
running_time:
 enable: true
 create_time: '07/25/2019 12:00:00' #此处修改你的建站时间或者网站上线时间

2.修改\themes\yilia\layout\_partial\footer.ejs,在</footer>上面添加如下内容:

<!--《添加网站运行时间  <br/>-->
<% if (theme.running_time && theme.running_time.enable && theme.running_time.create_time){ %>
    <span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
    <script>
    var now = new Date();

    function createtime() {
        //此处修改你的建站时间或者网站上线时间
        var create_time = '<%- theme.running_time.create_time %>';
        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("timeDate").innerHTML = " | 本站已安全运行 " + dnum + " 天 ";
        document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
    }
    setInterval("createtime()", 250);
    </script>
<% } %>
<!-- 添加网站运行时间》-->

效果

本站已安全运行 101 天 12 小时 13 分 41 秒

2.添加ICP备案信息

添加位置建议:底部第首行。如果有统计量、运行时间前面。没有就按照下面的建议。

参考:Hexo博客页脚添加ICP备案号

1.修改\themes\yilia\_config.yml,添加如下内容:

# ICP备案信息(英文全称:Internet Content Provider,中文全称:网络内容提供商。)
# 参考:https://blog.csdn.net/qq_37449342/article/details/95649140
# 粤ICP备00000000号
icp:
 enable: true
 id: '粤ICP备00000000号'  # 备案号

2.修改\themes\yilia\layout\_partial\footer.ejs,在</footer>上面添加如下内容:

<!-- 《网站备案号 -->
<% if (theme.icp && theme.icp.enable && theme.icp.id){ %>
    <div class="BeiAn-info">
        <img src="https://static.dy208.cn/o_1dfilp8ruo521thr1hvf18ji17soa.png" title="备案管理系统">
        <a href="http://www.beian.miit.gov.cn/" style="color:#f72b07" target="_blank" title="备案号">
            <%- theme.icp.id %>
        </a>
    </div>
<% } %>
<!-- 网站备案号》 -->

图标也可为:http://www.beian.miit.gov.cn/images/top/0.png

效果

file

3.设定站点建立时间

参考:

这个时间将在站点的底部显示,如果建站时间小于当前时间(年份),形式为:@ 2018 - 2019;否则默认为当前年份,如:@2019
编辑主题的 \themes\yilia\_config.yml(在hexo根目录的配置文件中也可以),新增字段 since

# Year of Site Creation | 网站成立年份
# 设定站点建立时间,这个时间将在站点的底部显示,如果是当年显示为 @ 2019,否则显示为时间段 © 2018 - 2019。
since: 2019

对应的配置文件H:\Hexo\themes\yilia\layout\_partial\footer.ejs的原内容(部分内容,主要是<div class="footer-left">标签内容):

<footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
    		&copy; <%= date(new Date(), 'YYYY') %> <%= config.author || config.title %>
    	</div>
      	<div class="footer-right">
      		<a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
      	</div>
    </div>
  </div>

存在问题:小于时,不能正常显示(/按照需求显示)。修改后:

<footer id="footer">
  <div class="outer">
    <div id="footer-info">
    	<div class="footer-left">
            <!--如果有设置theme.since,并且时间小于当前时间(年份),形式为:@ 2018 - 2019(+作者/标题);否则默认为当前年份(+作者/标题)。 -->
    		<% if (theme.since && !isNaN(theme.since) && theme.since < date(new Date(), 'YYYY')) { %>
                &copy; <%- theme.since %>-<%= date(new Date(), 'YYYY') %>
            <% } else { %>
                &copy; <%= date(new Date(), 'YYYY') %>
            <% } %>
            <%= config.author || config.title %>
    	</div>

效果

如:since: 2018显示为@ 2018 - 2019;否则默认为当前年份,如:@2019


文章首发于:hexo+yilia添加网站运行时间,ICP备案信息,设定站点建立时间

发布了132 篇原创文章 · 获赞 149 · 访问量 19万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章