Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4c1dcb8

Browse files
committed
文章加上预计阅读时间
1 parent e35993c commit 4c1dcb8

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

template/articles/detail.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ <h1>
2828
{{else}}
2929
<span>{{.article.AuthorTxt}}</span>
3030
{{end}}
31-
· <span title="{{.article.Ctime}}" class="timeago"></span> · {{.article.Viewnum}} 次点击 &nbsp; &nbsp;
31+
· <span title="{{.article.Ctime}}" class="timeago"></span> · {{.article.Viewnum}} 次点击 ·
32+
<span class="read-time"></span> ·
33+
<span class="timeago" title="{{.cur_time}}"></span> 开始浏览 &nbsp; &nbsp;
3234
{{if canEdit .me .article}}
3335
<a id="edit" class="op" href="javascript:" title="编辑">编辑</a>
3436
{{end}}
3537
</small>
36-
<small class="gray" style="margin-left: 20px;"><span class="timeago" title="{{.cur_time}}"></span> 开始浏览</small>
3738
</div>
3839
{{if gt (distanceDay .article.Ctime) 100 }}
3940
<div class="outdated">这是一个创建于 <span title="{{.article.Ctime}}" class="timeago"></span> 的文章,其中的信息可能已经有所发展或是发生改变。</div>
@@ -195,6 +196,14 @@ <h1>
195196
$(this).attr('href', url);
196197
$(this).attr('target', '_blank');
197198
});
199+
200+
var len = '{{.article.Txt}}'.length;
201+
var readTime = Math.round(len / 1200);
202+
if (readTime >= 1) {
203+
$('.read-time').text('预计阅读时间 '+readTime+' 分钟');
204+
} else {
205+
$('.read-time').text('预计阅读时间不到 1 分钟');
206+
}
198207
});
199208
</script>
200209
<script type="text/javascript" src="/static/ckeditor/config.js"></script>

template/topics/detail.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ <h1>
2323
{{.topic.title}}
2424
</h1>
2525
<small class="gray">
26-
<a href="/user/{{.topic.user.Username}}">{{.topic.user.Username}}</a> · <span title="{{.topic.ctime}}" class="timeago"></span> · {{add .topic.view 1}} 次点击 &nbsp; &nbsp;
26+
<a href="/user/{{.topic.user.Username}}">{{.topic.user.Username}}</a> · <span title="{{.topic.ctime}}" class="timeago"></span> · {{add .topic.view 1}} 次点击 ·
27+
<span class="timeago" title="{{.cur_time}}"></span> 开始浏览&nbsp; &nbsp;
2728
{{if canEdit .me .topic}}
2829
<a class="op" href="/topics/modify?tid={{.topic.tid}}" title="编辑">编辑</a>
2930
{{end}}
3031
</small>
31-
<small class="gray" style="margin-left: 20px;"><span class="timeago" title="{{.cur_time}}"></span> 开始浏览</small>
3232
</div>
3333
{{if gt (distanceDay .topic.ctime) 100 }}
3434
<div class="outdated">这是一个创建于 <span title="{{.topic.ctime}}" class="timeago"></span> 的主题,其中的信息可能已经有所发展或是发生改变。</div>

0 commit comments

Comments
 (0)