2025-04-02 23:04:09 +01:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"regexp"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type (
|
2025-11-08 12:54:31 +00:00
|
|
|
BlueskyRecord struct {
|
|
|
|
|
ActorDID string `json:"actor"`
|
|
|
|
|
RecordID string `json:"record"`
|
|
|
|
|
}
|
|
|
|
|
FediverseActivity struct {
|
|
|
|
|
AccountID string `json:"account"`
|
|
|
|
|
StatusID string `json:"status"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlogAuthor struct {
|
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
DisplayName string `json:"display_name"`
|
|
|
|
|
AvatarURL string `json:"avatar_url"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 01:32:30 +01:00
|
|
|
BlogPost struct {
|
2025-11-08 12:54:31 +00:00
|
|
|
ID string `json:"id"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
Visible bool `json:"visible"`
|
|
|
|
|
PublishDate time.Time `json:"publish_date"`
|
|
|
|
|
Author BlogAuthor `json:"author"`
|
|
|
|
|
Markdown string `json:"markdown"`
|
|
|
|
|
Bluesky *BlueskyRecord `json:"bluesky"`
|
|
|
|
|
Fediverse *FediverseActivity `json:"fediverse"`
|
2025-04-02 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
|
2025-06-24 01:32:30 +01:00
|
|
|
func (b *BlogPost) TitleNormalised() string {
|
2025-04-02 23:04:09 +01:00
|
|
|
rgx := regexp.MustCompile(`[^a-z0-9\-]`)
|
|
|
|
|
return rgx.ReplaceAllString(
|
|
|
|
|
strings.ReplaceAll(
|
|
|
|
|
strings.ToLower(b.Title), " ", "-",
|
|
|
|
|
),
|
|
|
|
|
"",
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-24 01:32:30 +01:00
|
|
|
func (b *BlogPost) GetMonth() string {
|
2025-11-08 12:54:31 +00:00
|
|
|
return fmt.Sprintf("%02d", int(b.PublishDate.Month()))
|
2025-04-02 23:04:09 +01:00
|
|
|
}
|
|
|
|
|
|
2025-06-24 01:32:30 +01:00
|
|
|
func (b *BlogPost) PrintDate() string {
|
2025-11-08 18:42:02 +00:00
|
|
|
return b.PublishDate.Format("02 January 2006, 15:04")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *BlogPost) PrintShortDate() string {
|
|
|
|
|
return b.PublishDate.Format("2 Jan 2006")
|
2025-06-24 01:32:30 +01:00
|
|
|
}
|
|
|
|
|
|
2025-11-08 12:54:31 +00:00
|
|
|
func (b *BlogPost) TextPublishDate() string {
|
|
|
|
|
return b.PublishDate.Format("2006-01-02T15:04")
|
2025-04-02 23:04:09 +01:00
|
|
|
}
|