diff --git a/pkg/cache/cache.go b/pkg/cache/cache.go index 4cf3e6f..fa31653 100644 --- a/pkg/cache/cache.go +++ b/pkg/cache/cache.go @@ -234,8 +234,8 @@ func (c *Cache) rebuildArticle(article *model.Article, needSort bool) { } } // series - for i, series := range c.Series { - if series.ID == article.SeriesID { + for i, serie := range c.Series { + if serie.ID == article.SerieID { c.Series[i].Articles = append(c.Series[i].Articles, article) if needSort { sort.Sort(c.Series[i].Articles) @@ -291,7 +291,7 @@ func (c *Cache) regeneratePages() { case pageArchive: sort.Sort(c.Archives) buf := bytes.Buffer{} - buf.WriteString(c.Blogger.ArchiveSay + "\n") + buf.WriteString(c.Blogger.ArchivesSay + "\n") var ( currentYear string gt12Month = len(Ei.Archives) > 12 diff --git a/pkg/cache/store/mongodb.go b/pkg/cache/store/mongodb.go index 70c440c..7acd274 100644 --- a/pkg/cache/store/mongodb.go +++ b/pkg/cache/store/mongodb.go @@ -25,7 +25,7 @@ const ( collectionArticle = "article" collectionBlogger = "blogger" collectionCounter = "counter" - collectionSeries = "series" + collectionSerie = "serie" counterNameSerie = "serie" counterNameArticle = "article" @@ -69,7 +69,7 @@ func (db *mongodb) Init(source string) (Store, error) { Keys: bson.D{bson.E{Key: "slug", Value: 1}}, Options: options.Index().SetUnique(true).SetSparse(true), } - db.Database(mongoDBName).Collection(collectionSeries). + db.Database(mongoDBName).Collection(collectionSerie). Indexes(). CreateOne(context.Background(), indexModel) return db, nil @@ -149,29 +149,29 @@ func (db *mongodb) UpdateAccount(ctx context.Context, name string, return err } -// InsertSeries 创建专题 -func (db *mongodb) InsertSeries(ctx context.Context, series *model.Series) error { - collection := db.Database(mongoDBName).Collection(collectionSeries) +// InsertSerie 创建专题 +func (db *mongodb) InsertSerie(ctx context.Context, serie *model.Serie) error { + collection := db.Database(mongoDBName).Collection(collectionSerie) - series.ID = db.nextValue(ctx, counterNameSerie) - _, err := collection.InsertOne(ctx, series) + serie.ID = db.nextValue(ctx, counterNameSerie) + _, err := collection.InsertOne(ctx, serie) return err } -// RemoveSeries 删除专题 -func (db *mongodb) RemoveSeries(ctx context.Context, id int) error { - collection := db.Database(mongoDBName).Collection(collectionSeries) +// RemoveSerie 删除专题 +func (db *mongodb) RemoveSerie(ctx context.Context, id int) error { + collection := db.Database(mongoDBName).Collection(collectionSerie) filter := bson.M{"id": id} _, err := collection.DeleteOne(ctx, filter) return err } -// UpdateSeries 更新专题 -func (db *mongodb) UpdateSeries(ctx context.Context, id int, +// UpdateSerie 更新专题 +func (db *mongodb) UpdateSerie(ctx context.Context, id int, fields map[string]interface{}) error { - collection := db.Database(mongoDBName).Collection(collectionSeries) + collection := db.Database(mongoDBName).Collection(collectionSerie) filter := bson.M{"id": id} params := bson.M{} @@ -183,9 +183,9 @@ func (db *mongodb) UpdateSeries(ctx context.Context, id int, return err } -// LoadAllSeries 查询所有专题 -func (db *mongodb) LoadAllSeries(ctx context.Context) (model.SortedSeries, error) { - collection := db.Database(mongoDBName).Collection(collectionSeries) +// LoadAllSerie 查询所有专题 +func (db *mongodb) LoadAllSerie(ctx context.Context) (model.SortedSeries, error) { + collection := db.Database(mongoDBName).Collection(collectionSerie) filter := bson.M{} cur, err := collection.Find(ctx, filter) @@ -196,7 +196,7 @@ func (db *mongodb) LoadAllSeries(ctx context.Context) (model.SortedSeries, error var series model.SortedSeries for cur.Next(ctx) { - obj := model.Series{} + obj := model.Serie{} err = cur.Decode(&obj) if err != nil { return nil, err diff --git a/pkg/cache/store/store.go b/pkg/cache/store/store.go index 8d2b7b3..2ac083c 100644 --- a/pkg/cache/store/store.go +++ b/pkg/cache/store/store.go @@ -27,14 +27,14 @@ type Store interface { // UpdateAccount 更新账户 UpdateAccount(ctx context.Context, name string, fields map[string]interface{}) error - // InsertSeries 创建专题 - InsertSeries(ctx context.Context, series *model.Series) error - // RemoveSeries 删除专题 - RemoveSeries(ctx context.Context, id int) error - // UpdateSeries 更新专题 - UpdateSeries(ctx context.Context, id int, fields map[string]interface{}) error - // LoadAllSeries 读取所有专题 - LoadAllSeries(ctx context.Context) (model.SortedSeries, error) + // InsertSerie 创建专题 + InsertSerie(ctx context.Context, series *model.Serie) error + // RemoveSerie 删除专题 + RemoveSerie(ctx context.Context, id int) error + // UpdateSerie 更新专题 + UpdateSerie(ctx context.Context, id int, fields map[string]interface{}) error + // LoadAllSerie 读取所有专题 + LoadAllSerie(ctx context.Context) (model.SortedSeries, error) // InsertArticle 创建文章 InsertArticle(ctx context.Context, article *model.Article) error diff --git a/pkg/core/blog/page/fe.go b/pkg/core/blog/page/fe.go index 7b8e265..7ef478a 100644 --- a/pkg/core/blog/page/fe.go +++ b/pkg/core/blog/page/fe.go @@ -101,9 +101,9 @@ func handleArticlePage(c *gin.Context) { } else { params["Days"] = int(time.Now().Sub(article.CreatedAt).Hours()) / 24 } - if article.SeriesID > 0 { + if article.SerieID > 0 { for _, series := range cache.Ei.Series { - if series.ID == article.SeriesID { + if series.ID == article.SerieID { params["Serie"] = series } } diff --git a/pkg/model/article.go b/pkg/model/article.go index a53159c..a6c8ea6 100644 --- a/pkg/model/article.go +++ b/pkg/model/article.go @@ -7,15 +7,15 @@ import "time" // Article 文章 type Article struct { - ID int `gorm:"column:id;primaryKey" bson:"id"` // 自增ID - Author string `gorm:"column:author;not null" bson:"author"` // 作者名 - Slug string `gorm:"column:slug;not null;uniqueIndex" bson:"slug"` // 文章缩略名 - Title string `gorm:"column:title;not null" bson:"title"` // 标题 - Count int `gorm:"column:count;not null" bson:"count"` // 评论数量 - Content string `gorm:"column:content;not null" bson:"content"` // markdown内容 - SeriesID int `gorm:"column:series_id;not null" bson:"series_id"` // 专题ID - Tags string `gorm:"column:tags;not null" bson:"tags"` // tag,以逗号隔开 - IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿 + ID int `gorm:"column:id;primaryKey" bson:"id"` // 自增ID + Author string `gorm:"column:author;not null" bson:"author"` // 作者名 + Slug string `gorm:"column:slug;not null;uniqueIndex" bson:"slug"` // 文章缩略名 + Title string `gorm:"column:title;not null" bson:"title"` // 标题 + Count int `gorm:"column:count;not null" bson:"count"` // 评论数量 + Content string `gorm:"column:content;not null" bson:"content"` // markdown内容 + SerieID int `gorm:"column:serie_id;not null" bson:"serie_id"` // 专题ID + Tags string `gorm:"column:tags;not null" bson:"tags"` // tag,以逗号隔开 + IsDraft bool `gorm:"column:is_draft;not null" bson:"is_draft"` // 是否是草稿 DeletedAt time.Time `gorm:"column:deleted_at;default:null" bson:"deleted_at"` // 删除时间 UpdatedAt time.Time `gorm:"column:updated_at;default:now()" bson:"updated_at"` // 更新时间 diff --git a/pkg/model/blogger.go b/pkg/model/blogger.go index 5d33bf3..b8edcee 100644 --- a/pkg/model/blogger.go +++ b/pkg/model/blogger.go @@ -9,6 +9,6 @@ type Blogger struct { BTitle string `gorm:"column:b_title;not null" bson:"b_title"` // 底部title Copyright string `gorm:"column:copyright;not null" bson:"copyright"` // 版权声明 - SeriesSay string `gorm:"column:series_say;not null" bson:"series_say"` // 专题说明 - ArchiveSay string `gorm:"column:archive_say;not null" bson:"archive_say"` // 归档说明 + SeriesSay string `gorm:"column:series_say;not null" bson:"series_say"` // 专题说明 + ArchivesSay string `gorm:"column:archives_say;not null" bson:"archives_say"` // 归档说明 } diff --git a/pkg/model/series.go b/pkg/model/series.go index 0f65861..ed48840 100644 --- a/pkg/model/series.go +++ b/pkg/model/series.go @@ -3,8 +3,8 @@ package model import "time" -// Series 专题 -type Series struct { +// Serie 专题 +type Serie struct { ID int `gorm:"column:id;primaryKey" bson:"id"` // 自增ID Slug string `gorm:"column:slug;not null;uniqueIndex" bson:"slug"` // 缩略名 Name string `gorm:"column:name;not null" bson:"name"` // 专题名 @@ -15,7 +15,7 @@ type Series struct { } // SortedSeries 排序后专题 -type SortedSeries []*Series +type SortedSeries []*Serie // Len 长度 func (s SortedSeries) Len() int { return len(s) } diff --git a/website/admin/draft.html b/website/admin/draft.html index 9f2981d..af87ceb 100644 --- a/website/admin/draft.html +++ b/website/admin/draft.html @@ -50,8 +50,8 @@
- +
{{.SubTitle}}
-最后登录: {{dateformat .LoginTime "2006/01/02 15:04"}}
+最后登录: {{dateformat .LoginAt "2006/01/02 15:04"}}