本文最后更新于:2022年4月4日 晚上
为Fluid模板添加运行时间尾标 时间计算代码源自网络,点此直达 。 最近学业繁忙,先记下简单步骤,这几天有时间尝试贡献到github社区。 本人并非编程专业,只是刚开始接触的爱好者,如有纰漏请多多指正。
1. 在\themes\fluid\layout\_partial
路径下创建timer.ejs
文件,将代码复制进去。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 <div class ="timer" > <span id ="sitetime" > </span > <script language =javascript > function siteTime ( ){ window .setTimeout ("siteTime()" , 1000 ); var seconds = 1000 ; var minutes = seconds * 60 ; var hours = minutes * 60 ; var days = hours * 24 ; var years = days * 365 ; var today = new Date (); var todayYear = today.getFullYear (); var todayMonth = today.getMonth ()+1 ; var todayDate = today.getDate (); var todayHour = today.getHours (); var todayMinute = today.getMinutes (); var todaySecond = today.getSeconds (); var t1 = Date .UTC (2022 ,04 ,02 ,00 ,18 ,13 ); var t2 = Date .UTC (todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond); var diff = t2-t1; var diffYears = Math .floor (diff/years); var diffDays = Math .floor ((diff/days)-diffYears*365 ); var diffHours = Math .floor ((diff-(diffYears*365 +diffDays)*days)/hours); var diffMinutes = Math .floor ((diff-(diffYears*365 +diffDays)*days-diffHours*hours)/minutes); var diffSeconds = Math .floor ((diff-(diffYears*365 +diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds); document .getElementById ("sitetime" ).innerHTML =" 已运行 " +diffDays+" 天 " +diffHours+" 小时 " +diffMinutes+" 分钟 " +diffSeconds+" 秒" ; } siteTime (); </script >
框1
1 2 3 4 5 6 7 8 9 10 11 12 <footer class ="text-center mt-5 py-3" > <div class ="footer-content" > <%- theme.footer.content %> </div > 此处插入下框代码 <%- partial('_partial/statistics.ejs' ) %> <%- partial('_partial/beian.ejs' ) %> <% if (theme.web_analytics.cnzz) { %> <span id ="cnzz_stat_icon_<%= theme.web_analytics.cnzz %>" style ="display: none" ></span > <% } %> </footer >
框2
1 2 3 4 <div class ="timer" > <%- partial('_partial/timer.ejs' ) %> </div >
大功告成!
## 3.在`\themes\fluid`路径下打开`_config.yml`文件。注意
不是根目录的!
找到第395行,名为footer。在框1后面插入框2代码。
框1
1 2 3 4 5 6 7 footer: content: ' <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener" ><span>Theme-Fluid</span ></a > ' 从此行开始插入,注意缩进,让timer和content对齐。
框2