回忆是一座桥
却是通往寂寞的牢

Hexo Fluid主题添加网站运行时间与版权声明优化

版权声明优化

fluid里原本的版权声明不包含文章作者与文章链接,不够全面,因此可以按照以下步骤优化版权声明:

1、在fluid主题目录下里找到/layout/post.ejs文件,并从文件中找到以下内容:

    <% if(theme.post.copyright.enable && theme.post.copyright.content && page.copyright !== false) { %>
    <p class="note note-warning">
      <% if (typeof page.copyright === 'string' && page.copyright !== '') { %>
        <%- page.copyright %>
      <% } else { %>
        <%- theme.post.copyright.content %>
      <% } %>
    </p>
    <% } %>

2、然后,把上面的内容修改成如下:

<% if(theme.post.copyright.enable && theme.post.copyright.content && page.copyright !== false) { %>
<p class="note note-warning">
  <% if (typeof page.copyright === 'string' && page.copyright !== '') { %>
    <%- page.copyright %>
  <% } else { %>
    <strong>本文作者: </strong><a href="<%- url_for() %>"><%- theme.about.name || config.author || config.title %></a> <br>
    <strong>本文链接: </strong><a href="<%- full_url_for(page.path) %>"><%-          full_url_for(page.path) %></a> <br>
    <strong>版权声明: </strong><%- theme.post.copyright.content %>
  <% } %>
</p>
<% } %>

添加网站运行时间

1、打开主题目录下的/layout/_partial文件夹,在其中创建runtime.ejs文件,文件内容如下:

<div>
<span id="timeDate">载入天数...</span>
<span id="times">载入时分秒...</span>
<script>
var now = new Date();
function createtime(){
  var grt= new Date("06/23/2021 00: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>
</div>

2、打开主题目录下的/layout/_partial/footer.ejs文件,在其中某个合适位置载入runtime.ejs文件,具体如下:

<footer class="text-center mt-5 py-3">
  <div class="footer-content">
    <%- theme.footer.content %>
  </div>
  <%- partial('_partial/runtime.ejs') %>        // 例如,在此处加载runtime.ejs文件

  <%- partial('_partial/statistics.ejs') %>
  <%- partial('_partial/beian.ejs') %>
  <% if(theme.web_analytics.cnzz) { %>
    <!-- cnzz Analytics Icon -->
    <span id="cnzz_stat_icon_<%- theme.web_analytics.cnzz %>" style="display: none"></span>
  <% } %>
</footer>

检查是否配置成功

使用以下命令检查是否配置成功:

hexo clean
hexo g
hexo s

若配置成功,则上传到网站根目录:

hexo d
未经允许不得转载:夕枫 » Hexo Fluid主题添加网站运行时间与版权声明优化
订阅评论
提醒
guest
1 评论
最新
最久 最赞
内联反馈
查看所有评论