fix article list error

This commit is contained in:
deepzz0
2016-12-08 23:15:40 +08:00
parent adbe1b97f4
commit 01335ea06c
5 changed files with 25 additions and 20 deletions

24
api.go
View File

@@ -194,14 +194,13 @@ func apiPostAdd(c *gin.Context) {
if tag != "" { if tag != "" {
tags = strings.Split(tag, ",") tags = strings.Split(tag, ",")
} }
t := CheckDate(date)
serieid := CheckSerieID(serie) serieid := CheckSerieID(serie)
publish = CheckPublish(do) publish = CheckPublish(do)
artc := &Article{ artc := &Article{
Title: title, Title: title,
Content: text, Content: text,
Slug: slug, Slug: slug,
CreateTime: t, CreateTime: CheckDate(date),
IsDraft: !publish, IsDraft: !publish,
Author: Ei.Username, Author: Ei.Username,
SerieID: serieid, SerieID: serieid,
@@ -222,16 +221,20 @@ func apiPostAdd(c *gin.Context) {
return return
} }
artc.ID = int32(cid) artc.ID = int32(cid)
if CheckBool(c.PostForm("update")) {
artc.UpdateTime = time.Now()
}
i, a := GetArticle(artc.ID) i, a := GetArticle(artc.ID)
if a != nil { if a != nil {
artc.IsDraft = false artc.IsDraft = false
artc.Count = a.Count artc.Count = a.Count
artc.UpdateTime = a.UpdateTime artc.UpdateTime = a.UpdateTime
Ei.Articles = append(Ei.Articles[0:i], Ei.Articles[i+1:]...)
DelFromLinkedList(a)
ManageTagsArticle(a, false, DELETE)
ManageSeriesArticle(a, false, DELETE)
ManageArchivesArticle(a, false, DELETE)
delete(Ei.MapArticles, a.Slug)
a = nil
} }
if update != "" { if CheckBool(update) {
artc.UpdateTime = time.Now() artc.UpdateTime = time.Now()
} }
err = UpdateArticle(bson.M{"id": artc.ID}, artc) err = UpdateArticle(bson.M{"id": artc.ID}, artc)
@@ -240,15 +243,6 @@ func apiPostAdd(c *gin.Context) {
return return
} }
if !artc.IsDraft { if !artc.IsDraft {
if a != nil {
Ei.Articles = append(Ei.Articles[0:i], Ei.Articles[i+1:]...)
DelFromLinkedList(a)
ManageTagsArticle(a, false, DELETE)
ManageSeriesArticle(a, false, DELETE)
ManageArchivesArticle(a, false, DELETE)
delete(Ei.MapArticles, a.Slug)
a = nil
}
Ei.MapArticles[artc.Slug] = artc Ei.MapArticles[artc.Slug] = artc
Ei.Articles = append(Ei.Articles, artc) Ei.Articles = append(Ei.Articles, artc)
sort.Sort(Ei.Articles) sort.Sort(Ei.Articles)

View File

@@ -61,7 +61,7 @@ func HandleLoginPost(c *gin.Context) {
return return
} }
if Ei.Username != user || !VerifyPasswd(Ei.Password, user, pwd) { if Ei.Username != user || !VerifyPasswd(Ei.Password, user, pwd) {
logd.Print("账号或密码错误", user, pwd) logd.Printf("账号或密码错误 %s, %s", user, pwd)
c.Redirect(http.StatusFound, "/admin/login") c.Redirect(http.StatusFound, "/admin/login")
return return
} }
@@ -105,7 +105,7 @@ func HandlePost(c *gin.Context) {
h["Edit"] = artc h["Edit"] = artc
} }
} }
if h["Title"] == "" { if h["Title"] == nil {
h["Title"] = "撰写文章 | " + Ei.BTitle h["Title"] = "撰写文章 | " + Ei.BTitle
} }
h["Path"] = c.Request.URL.Path h["Path"] = c.Request.URL.Path

View File

@@ -3,7 +3,7 @@ runmode: prod
# 回收箱保留48小时 # 回收箱保留48小时
trash: -48 trash: -48
# 定时清理回收箱,%d小时 # 定时清理回收箱,%d小时
clean: 12 clean: 1
# 首页展示文章数量 # 首页展示文章数量
pagenum: 10 pagenum: 10
# 管理界面 # 管理界面

13
db.go
View File

@@ -73,7 +73,17 @@ func init() {
ms.Close() ms.Close()
ms, c = db.Connect(DB, COLLECTION_ARTICLE) ms, c = db.Connect(DB, COLLECTION_ARTICLE)
index = mgo.Index{ index = mgo.Index{
Key: []string{"id", "slug"}, Key: []string{"id"},
Unique: true,
DropDups: true,
Background: true,
Sparse: true,
}
if err := c.EnsureIndex(index); err != nil {
logd.Fatal(err)
}
index = mgo.Index{
Key: []string{"slug"},
Unique: true, Unique: true,
DropDups: true, DropDups: true,
Background: true, Background: true,
@@ -461,6 +471,7 @@ func AddToLinkedList(id int32) {
artc.Prev = Ei.Articles[i-1] artc.Prev = Ei.Articles[i-1]
if Ei.Articles[i-1].Next != nil { if Ei.Articles[i-1].Next != nil {
artc.Next = Ei.Articles[i-1].Next artc.Next = Ei.Articles[i-1].Next
Ei.Articles[i-1].Next.Prev = artc
} }
Ei.Articles[i-1].Next = artc Ei.Articles[i-1].Next = artc
} }

View File

@@ -23,7 +23,7 @@
个人邮箱</label> 个人邮箱</label>
<input id="info-0-1" name="email" type="text" class="text" value="{{.Email}}" /> <input id="info-0-1" name="email" type="text" class="text" value="{{.Email}}" />
<p class="description"> <p class="description">
用于发送告警邮件及其它通知, 建议填写, 如: example#163.com.</p> 用于发送告警邮件及其它通知, 建议填写, 如: example@163.com.</p>
</li> </li>
</ul> </ul>
<ul class="typecho-option"> <ul class="typecho-option">