@@ -50,11 +50,12 @@ <h3><a href="/resources">最新资源</a></h3>
50
50
51
51
< div class ="row box_white article-list ">
52
52
< ul class ="nav nav-tabs " role ="tablist " id ="article-nav ">
53
- < li role ="presentation " class ="active "> < a href ="/ "> 最新博文</ a > </ li >
54
- < li role ="presentation " class =" rank " data-type ="today "> < a href ="# "> 今日热门</ a > </ li >
55
- < li role ="presentation " class =" rank " data-type ="yesterday "> < a href ="# "> 昨日热门</ a > </ li >
56
- < li role ="presentation " class =" rank " data-type ="week "> < a href ="# "> 一周热门</ a > </ li >
53
+ < li role ="presentation " class ="active " data-type =" newest " > < a href ="javascript: "> 最新博文</ a > </ li >
54
+ < li role ="presentation " data-type ="today "> < a href ="javascript: "> 今日热门</ a > </ li >
55
+ < li role ="presentation " data-type ="yesterday "> < a href ="javascript: "> 昨日热门</ a > </ li >
56
+ < li role ="presentation " data-type ="week "> < a href ="javascript: "> 一周热门</ a > </ li >
57
57
</ ul >
58
+ < div id ="article-list ">
58
59
{{range .articles}}
59
60
< article class ="article box_white ">
60
61
< div class ="row ">
@@ -123,10 +124,13 @@ <h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">
123
124
< div class ="row "> 暂无博文,< a class ="btn btn-default btn-sm " href ="/articles/new "> 撰写文章</ a > </ div >
124
125
</ article >
125
126
{{end}}
127
+
126
128
{{if (len .articles) gt 0}}
127
129
{{$article := index .articles 0}}
128
130
< div class ="pull-right article-bottom "> < a href ="/articles?lastid={{add $article.Id -10}} " title ="查看更多 "> 查看更多>></ a > </ div >
129
131
{{end}}
132
+
133
+ </ div >
130
134
</ div >
131
135
< div class ="row box_white book-list ">
132
136
< div class ="title ">
@@ -321,12 +325,58 @@ <h3 class="title"><i class="glyphicon glyphicon-link"></i> 友情链接</h3
321
325
322
326
</ div >
323
327
</ div >
328
+
329
+ < script type ="text/x-jsrender " id ="article-tpl ">
330
+ < article class = "article box_white" >
331
+ < div class = "row" >
332
+ [%if cover%]
333
+ < div class = "pull-left" >
334
+ < a href = "/articles/[%:id%]" target = "_blank" title = "[%:title%]" >
335
+ < img class = "lazy" src = "[%:cover%]" width = "200" alt = "[%:title%]" style = "display: inline;" >
336
+ </ a >
337
+ </ div >
338
+ < div style = "margin-left:220px;" >
339
+ [%else%]
340
+ < div >
341
+ [%/if%]
342
+ < h2 > < a href = "/articles/[%:id%]" target = "_blank" title = "[%:title%]" >
343
+ [%:title%]
344
+ </ a > </ h2 >
345
+ < p class = "text" > [%:txt%]< a href = "/articles/[%:id%]" target = "_blank" title = "阅读全文" > 阅读全文</ a > </ p >
346
+ </ div >
347
+ </ div >
348
+ < div class = "row" >
349
+ < div class = "col-md-8 metatag" >
350
+ < i class = "glyphicon glyphicon-th" > </ i >
351
+ < span class = "source" title = "来源" > [%:name%]</ span >
352
+ < i class = "glyphicon glyphicon-calendar" > </ i >
353
+ < span class = "date" title = "发布日期" > [%:pub_date%]</ span >
354
+ < i class = "glyphicon glyphicon-user" > </ i >
355
+ < span class = "author" title = "作者" > [%:author_txt%]</ span >
356
+ </ div >
357
+ < div class = "col-md-4 metatag text-right" >
358
+ < span class = "view" title = "阅读数" >
359
+ < i class = "glyphicon glyphicon-eye-open" > </ i >
360
+ 阅读:< span > [%:rank_view%]</ span > 次
361
+ </ span >
362
+ </ div >
363
+ </ div >
364
+ </ article >
365
+ </ script >
366
+
367
+ < script type ="text/x-jsrender " id ="no-article-tpl ">
368
+ < article class = "article box_white" >
369
+ < div class = "row" > 该排行榜暂无博文</ div >
370
+ </ article >
371
+ </ script >
372
+
324
373
{{end}}
325
374
{{define "css"}}
326
375
< link href ="/static/css/index.css?v=0.4 " rel ="stylesheet "/>
327
376
{{end}}
328
377
{{define "js"}}
329
378
< script type ="text/javascript " src ="/static/js/index.js?v=0.5 "> </ script >
379
+ < script type ="text/javascript " src ="//cdnjs.cloudflare.com/ajax/libs/jsrender/0.9.84/jsrender.min.js "> </ script >
330
380
< script type ="text/javascript ">
331
381
// 需要加载的侧边栏
332
382
SG . SIDE_BARS = [
@@ -339,20 +389,40 @@ <h3 class="title"><i class="glyphicon glyphicon-link"></i> 友情链接</h3
339
389
"/friend/links"
340
390
] ;
341
391
392
+ $ . views . settings . delimiters ( "[%" , "%]" ) ;
393
+ // $.views.settings.debugMode(true);
394
+
342
395
$ ( function ( ) {
343
- $ ( '#article-nav .rank' ) . on ( 'click' , function ( evt ) {
396
+
397
+ var newestArticleHtml = '' ;
398
+
399
+ $ ( '#article-nav li' ) . on ( 'click' , function ( evt ) {
344
400
evt . preventDefault ( ) ;
345
401
346
402
$ ( this ) . parent ( ) . children ( ) . removeClass ( 'active' ) ;
347
403
$ ( this ) . addClass ( 'active' ) ;
348
404
349
405
var type = $ ( this ) . data ( 'type' ) ;
350
406
407
+ if ( type != "newest" && newestArticleHtml == '' ) {
408
+ newestArticleHtml = $ ( '#article-list' ) . html ( ) ;
409
+ } else {
410
+ if ( type == "newest" ) {
411
+ $ ( '#article-list' ) . html ( newestArticleHtml ) ;
412
+ return ;
413
+ }
414
+ }
415
+
351
416
var params = { objtype : 1 , limit : 10 , rank_type : type }
352
417
$ . getJSON ( '/rank/view' , params , function ( result ) {
353
418
if ( result . ok ) {
354
419
var data = result . data ;
355
- console . log ( data ) ;
420
+ if ( data ) {
421
+ var rankArticlesHtml = $ . templates ( '#article-tpl' ) . render ( data ) ;
422
+ $ ( '#article-list' ) . html ( rankArticlesHtml ) ;
423
+ } else {
424
+ $ ( '#article-list' ) . html ( $ ( '#no-article-tpl' ) . html ( ) ) ;
425
+ }
356
426
}
357
427
} ) ;
358
428
} ) ;
0 commit comments