From 967a4843659b06ab6e15587759c8db85a258e481 Mon Sep 17 00:00:00 2001 From: Jimmy Kuu Date: Wed, 22 Oct 2014 14:45:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=BB=E9=A2=98=E7=BD=AE?= =?UTF-8?q?=E9=A1=B6=E5=AD=97=E6=AE=B5=E5=8F=8A=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gopher/config.go | 2 +- src/gopher/models.go | 1 + src/gopher/topic.go | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/gopher/config.go b/src/gopher/config.go index 2ae7c22..ce706d6 100644 --- a/src/gopher/config.go +++ b/src/gopher/config.go @@ -5,9 +5,9 @@ import ( "fmt" "html/template" "io/ioutil" + "log" "os" "runtime" - "log" "github.com/bradrydzewski/go.auth" ) diff --git a/src/gopher/models.go b/src/gopher/models.go index 35a2050..96c37fb 100644 --- a/src/gopher/models.go +++ b/src/gopher/models.go @@ -269,6 +269,7 @@ type Topic struct { NodeId bson.ObjectId LatestReplierId string LatestRepliedAt time.Time + IsTop bool `bson:"is_top"` // 置顶 } // 主题所属节点 diff --git a/src/gopher/topic.go b/src/gopher/topic.go index faccfd7..cb12378 100644 --- a/src/gopher/topic.go +++ b/src/gopher/topic.go @@ -35,6 +35,20 @@ func topicsHandler(handler Handler, conditions bson.M, sort string, url string, c = handler.DB.C(CONTENTS) + var topTopics []Topic + + if page == 1 { + c.Find(bson.M{"is_top": true}).Sort(sort).All(&topTopics) + + var objectIds []bson.ObjectId + for _, topic := range topTopics { + objectIds = append(objectIds, topic.Id_) + } + if len(topTopics) > 0 { + conditions["_id"] = bson.M{"$not": bson.M{"$in": objectIds}} + } + } + pagination := NewPagination(c.Find(conditions).Sort(sort), url, PerPage) var topics []Topic @@ -51,6 +65,8 @@ func topicsHandler(handler Handler, conditions bson.M, sort string, url string, c = handler.DB.C(LINK_EXCHANGES) c.Find(nil).All(&linkExchanges) + topics = append(topTopics, topics...) + renderTemplate(handler, "index.html", BASE, map[string]interface{}{ "nodes": hotNodes, "status": status,