package model import ( "database/sql" "fmt" "html/template" "regexp" "strings" "time" ) type ( BlogPost struct { ID string `db:"id"` Title string `db:"title"` Description string `db:"description"` Visible bool `db:"visible"` CreatedAt time.Time `db:"created_at"` ModifiedAt sql.NullTime `db:"modified_at"` AuthorID string `db:"author"` Markdown string `db:"markdown"` HTML template.HTML `db:"html"` BlueskyActorID *string `db:"bluesky_actor"` BlueskyPostID *string `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, 03:04") } func (b *BlogPost) PrintModifiedDate() string { if !b.ModifiedAt.Valid { return "" } return b.ModifiedAt.Time.Format("2 January 2006, 03:04") }