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

Skip to content

Commit 4eee4c8

Browse files
author
xuxinhua
committed
增加博文置顶功能
1 parent c4c3c80 commit 4eee4c8

File tree

7 files changed

+21
-2
lines changed

7 files changed

+21
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/github.com
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/github.com

websites/code/studygolang/src/model/article.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type Article struct {
3838
Viewnum int `json:"viewnum"`
3939
Cmtnum int `json:"cmtnum"`
4040
Likenum int `json:"likenum"`
41+
Top uint8 `json:"top"`
4142
Status int `json:"status"`
4243
OpUser string `json:"op_user"`
4344
Ctime string `json:"ctime"`
@@ -137,6 +138,7 @@ func (this *Article) colFieldMap() map[string]interface{} {
137138
"viewnum": &this.Viewnum,
138139
"cmtnum": &this.Cmtnum,
139140
"likenum": &this.Likenum,
141+
"top": &this.Top,
140142
"status": &this.Status,
141143
"op_user": &this.OpUser,
142144
"ctime": &this.Ctime,

websites/code/studygolang/src/service/article.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ func FindArticles(lastId, limit string) []*model.Article {
216216
return nil
217217
}
218218

219+
topArticles, err := article.Where("top=?", 1).Order("id DESC").FindAll()
220+
if err != nil {
221+
logger.Errorln("article service Find Top Articles Error:", err)
222+
return nil
223+
}
224+
if len(topArticles) > 0 {
225+
articleList = append(topArticles, articleList...)
226+
}
227+
219228
return articleList
220229
}
221230

websites/code/studygolang/template/articles/list.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
{{else}}
2424
<div>
2525
{{end}}
26-
<h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">{{.Title}}</a></h2>
26+
<h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">
27+
{{if .Top}}<font color="red">[置顶]</font>{{end}}{{.Title}}
28+
</a></h2>
2729
<p class="text">{{substring .Txt 250 "..."}}<a href="/articles/{{.Id}}" target="_blank" title="阅读全文">阅读全文</a></p>
2830
</div>
2931
</div>

websites/code/studygolang/template/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ <h3><a href="/articles">最新博文</a></h3>
5656
{{else}}
5757
<div>
5858
{{end}}
59-
<h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">{{.Title}}</a></h2>
59+
<h2><a href="/articles/{{.Id}}" target="_blank" title="{{.Title}}">
60+
{{if .Top}}<font color="red">[置顶]</font>{{end}}{{.Title}}
61+
</a></h2>
6062
<p class="text">{{substring .Txt 220 "..."}}<a href="/articles/{{.Id}}" target="_blank" title="阅读全文">阅读全文</a></p>
6163
</div>
6264
</div>

websites/databases/studygolang_db.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,14 @@ CREATE TABLE `articles` (
345345
`viewnum` int unsigned NOT NULL DEFAULT 0 COMMENT '浏览数',
346346
`cmtnum` int unsigned NOT NULL DEFAULT 0 COMMENT '评论数',
347347
`likenum` int unsigned NOT NULL DEFAULT 0 COMMENT '赞数',
348+
`top` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '置顶,0否,1置顶',
348349
`status` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '状态:0-初始抓取;1-已上线;2-下线(审核拒绝)',
349350
`op_user` varchar(20) NOT NULL DEFAULT '' COMMENT '操作人',
350351
`ctime` timestamp NOT NULL DEFAULT 0,
351352
`mtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
352353
PRIMARY KEY (`id`),
353354
UNIQUE KEY (`url`),
355+
KEY (`top`),
354356
KEY (`domain`),
355357
KEY (`ctime`)
356358
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '网络文章聚合表';

0 commit comments

Comments
 (0)