Features: - Tag system with multi-language support (Chinese/English) - Auto-create tags when associating with articles - Tag filtering on homepage with visual indicators - Full-text search across title, summary, and content - Tag cloud sidebar showing article counts - Search page with results display Technical Implementation: - Database models: Tag, ArticleTag (many-to-many) - Tag count caching for performance - Automatic tag slug generation - Responsive design with mobile support - I18n support for all new UI elements Bug Fix: - Fixed SQL column ambiguity error in tag filtering - Added table prefix to ORDER BY clause in publishedArticleOrder Routes: - GET /search - Search results page - GET /?tag=<slug> - Filter articles by tag - GET /api/articles?tag=<slug> - API with tag filter support Templates: - Added tag input field to article create/edit form - Added search box to homepage header - Added tag cloud sidebar on homepage and search page - Created new search results page template Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Article status constants.
|
|
const (
|
|
ArticleDraft = 0 // 草稿
|
|
ArticlePublished = 1 // 已发布
|
|
ArticleArchived = 2 // 已归档
|
|
)
|
|
|
|
// Article represents a blog post.
|
|
type Article struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"uniqueIndex:idx_slug_deleted_at" json:"deleted_at"`
|
|
AuthorID uint `gorm:"not null;index" json:"author_id"`
|
|
Title string `gorm:"not null;size:255" json:"title"`
|
|
Summary string `gorm:"size:512" json:"summary"`
|
|
Content string `gorm:"type:text;not null" json:"content"`
|
|
Cover string `gorm:"size:512" json:"cover"`
|
|
Status int `gorm:"default:0;index" json:"status"`
|
|
IsTop bool `gorm:"default:false" json:"is_top"`
|
|
ViewCount int `gorm:"default:0" json:"view_count"`
|
|
Slug string `gorm:"uniqueIndex:idx_slug_deleted_at;size:255" json:"slug"`
|
|
PublishedAt *time.Time `gorm:"index" json:"published_at"`
|
|
Author User `gorm:"foreignKey:AuthorID" json:"-"`
|
|
Tags []Tag `gorm:"many2many:article_tags;" json:"tags"`
|
|
}
|
|
|
|
// TableName overrides the default GORM table name.
|
|
func (Article) TableName() string {
|
|
return "articles"
|
|
}
|