package model import ( "database/sql" "fmt" "html/template" "regexp" "strings" "time" ) type ( BlogPost struct { ID string `json:"id" db:"id"` Title string `json:"title" db:"title"` Description string `json:"description" db:"description"` Visible bool `json:"visible" db:"visible"` CreatedAt time.Time `json:"created_at" db:"created_at"` ModifiedAt sql.NullTime `json:"modified_at" db:"modified_at"` AuthorID string `json:"author" db:"author"` Markdown string `json:"markdown" db:"markdown"` HTML template.HTML `json:"html" db:"html"` BlueskyActorID *string `json:"bluesky_actor" db:"bluesky_actor"` BlueskyPostID *string `json:"bluesky_post" db:"bluesky_post"` } ) func (b *BlogPost) TitleNormalised() string { rgx := regexp.MustCompile(`[^a-z0-9\-]`) return rgx.ReplaceAllString( strings.ReplaceAll( strings.ToLower(b.Title), " ", "-", ), "", ) } func (b *BlogPost) GetMonth() string { return fmt.Sprintf("%02d", int(b.CreatedAt.Month())) } func (b *BlogPost) PrintDate() string { return b.CreatedAt.Format("2 January 2006, 15:04") } func (b *BlogPost) PrintModifiedDate() string { if !b.ModifiedAt.Valid { return "" } return b.ModifiedAt.Time.Format("2 January 2006, 15:04") }