EJS - 1: Using EJS to show warning in expired article in Gridea

2020-01-24 Views EJS153字1 min read
featureimg

This article shows how to use EJS code to show warning in expired article in Gridea.

First, put this ejs code in your ejs file at an appropriate place:

<%- outputDate();%><%  -%>
<%
function refineContent(str){
   return str.replace("-","/");
}
function outputDate(){
let pDate= post.dateFormat;
pDate = refineContent(pDate);
var date2=new Date();
var date3=date2.getTime()-new Date(pDate).getTime();
var days=Math.floor(date3/(24*3600*1000));
if(days>=365){
content='<div class="warn"style="text-align:center">本文已超过 1 年没有更新,涉及的内容可能已经失效!</div>';
return content;
}
}

Then, using following css in your website:

.warn{
    overflow:hidden;
    margin:10px 0;
    padding:15px 15px 15px 35px;
    border:1px solid #eac946;
    background:#fff4b9 -1px -1px no-repeat;
    color:#ad9948;
    font-size:14px
}

Renderings:

Renderings
Renderings

Big Image
EOF
本文章采用CC BY-NC-SA 4.0进行许可。转载请注明出处!
上一篇

Data Structure - linkedList


下一篇

Data Structure - ArrayList