mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-17 20:02:27 +08:00
auto archiving by year when the month great than 12
This commit is contained in:
45
db.go
45
db.go
@@ -159,7 +159,8 @@ func generateMarkdown() {
|
|||||||
buffer.WriteString("\n\n")
|
buffer.WriteString("\n\n")
|
||||||
for _, artc := range serie.Articles {
|
for _, artc := range serie.Articles {
|
||||||
//eg. * [标题一](/post/hello-world.html) <span class="date">(Man 02, 2006)</span>
|
//eg. * [标题一](/post/hello-world.html) <span class="date">(Man 02, 2006)</span>
|
||||||
buffer.WriteString("* [" + artc.Title + "](/post/" + artc.Slug + ".html) <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
buffer.WriteString("* [" + artc.Title + "](/post/" + artc.Slug +
|
||||||
|
".html) <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
||||||
}
|
}
|
||||||
buffer.WriteByte('\n')
|
buffer.WriteByte('\n')
|
||||||
}
|
}
|
||||||
@@ -167,15 +168,31 @@ func generateMarkdown() {
|
|||||||
case ARCHIVE_MD:
|
case ARCHIVE_MD:
|
||||||
sort.Sort(Ei.Archives)
|
sort.Sort(Ei.Archives)
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
buffer.WriteString(Ei.ArchivesSay)
|
buffer.WriteString(Ei.ArchivesSay + "\n")
|
||||||
buffer.WriteString("\n\n")
|
|
||||||
|
var (
|
||||||
|
currentYear string
|
||||||
|
gt12Month = len(Ei.Archives) > 12
|
||||||
|
)
|
||||||
for _, archive := range Ei.Archives {
|
for _, archive := range Ei.Archives {
|
||||||
buffer.WriteString(fmt.Sprintf("### %s", archive.Time.Format("2006年01月")))
|
if gt12Month {
|
||||||
buffer.WriteString("\n\n")
|
year := archive.Time.Format("2006年")
|
||||||
for _, artc := range archive.Articles {
|
if currentYear != year {
|
||||||
buffer.WriteString("* [" + artc.Title + "](/post/" + artc.Slug + ".html) <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
currentYear = year
|
||||||
|
buffer.WriteString(fmt.Sprintf("\n### %s\n\n", archive.Time.Format("2006年")))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buffer.WriteString(fmt.Sprintf("\n### %s\n\n", archive.Time.Format("2006年2月")))
|
||||||
|
}
|
||||||
|
for i, artc := range archive.Articles {
|
||||||
|
if i == 0 && gt12Month {
|
||||||
|
buffer.WriteString("* *[" + artc.Title + "](/post/" + artc.Slug +
|
||||||
|
".html)* <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
||||||
|
} else {
|
||||||
|
buffer.WriteString("* [" + artc.Title + "](/post/" + artc.Slug +
|
||||||
|
".html) <span class=\"date\">(" + artc.CreateTime.Format("Jan 02, 2006") + ")</span>\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buffer.WriteByte('\n')
|
|
||||||
}
|
}
|
||||||
Ei.PageArchives = string(renderPage(buffer.Bytes()))
|
Ei.PageArchives = string(renderPage(buffer.Bytes()))
|
||||||
}
|
}
|
||||||
@@ -330,7 +347,8 @@ func upArticle(artc *Article, needSort bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ei.Archives = append(Ei.Archives, &Archive{Time: artc.CreateTime, Articles: SortArticles{artc}})
|
Ei.Archives = append(Ei.Archives, &Archive{Time: artc.CreateTime,
|
||||||
|
Articles: SortArticles{artc}})
|
||||||
if needSort {
|
if needSort {
|
||||||
Ei.CH <- ARCHIVE_MD
|
Ei.CH <- ARCHIVE_MD
|
||||||
}
|
}
|
||||||
@@ -494,7 +512,8 @@ func timer() {
|
|||||||
delT := time.NewTicker(time.Duration(setting.Conf.General.Clean) * time.Hour)
|
delT := time.NewTicker(time.Duration(setting.Conf.General.Clean) * time.Hour)
|
||||||
for {
|
for {
|
||||||
<-delT.C
|
<-delT.C
|
||||||
mgo.Remove(DB, COLLECTION_ARTICLE, mgo.M{"deletetime": mgo.M{"$gt": time.Time{}, "$lt": time.Now().Add(time.Duration(setting.Conf.General.Trash) * time.Hour)}})
|
mgo.Remove(DB, COLLECTION_ARTICLE, mgo.M{"deletetime": mgo.M{"$gt": time.Time{},
|
||||||
|
"$lt": time.Now().Add(time.Duration(setting.Conf.General.Trash) * time.Hour)}})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,7 +529,8 @@ func RemoveArticle(id int32) error {
|
|||||||
|
|
||||||
// 恢复删除文章到草稿箱
|
// 恢复删除文章到草稿箱
|
||||||
func RecoverArticle(id int32) error {
|
func RecoverArticle(id int32) error {
|
||||||
return mgo.Update(DB, COLLECTION_ARTICLE, mgo.M{"id": id}, mgo.M{"$set": mgo.M{"deletetime": time.Time{}, "isdraft": true}})
|
return mgo.Update(DB, COLLECTION_ARTICLE, mgo.M{"id": id},
|
||||||
|
mgo.M{"$set": mgo.M{"deletetime": time.Time{}, "isdraft": true}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新文章
|
// 更新文章
|
||||||
@@ -539,7 +559,8 @@ func AddSerie(name, slug, desc string) error {
|
|||||||
// 更新专题
|
// 更新专题
|
||||||
func UpdateSerie(serie *Serie) error {
|
func UpdateSerie(serie *Serie) error {
|
||||||
Ei.CH <- SERIES_MD
|
Ei.CH <- SERIES_MD
|
||||||
return mgo.Update(DB, COLLECTION_ACCOUNT, mgo.M{"username": Ei.Username, "blogger.series.id": serie.ID}, mgo.M{"$set": mgo.M{"blogger.series.$": serie}})
|
return mgo.Update(DB, COLLECTION_ACCOUNT, mgo.M{"username": Ei.Username,
|
||||||
|
"blogger.series.id": serie.ID}, mgo.M{"$set": mgo.M{"blogger.series.$": serie}})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除专题
|
// 删除专题
|
||||||
|
|||||||
Reference in New Issue
Block a user