blog visitor frontend (pretty much) done!

This commit is contained in:
ari melody 2025-06-24 01:32:30 +01:00
parent 3d64333b4f
commit faf6095d16
Signed by: ari
GPG key ID: CF99829C92678188
16 changed files with 903 additions and 463 deletions

View file

@ -1,6 +1,7 @@
package model
import (
"database/sql"
"fmt"
"html/template"
"regexp"
@ -9,20 +10,22 @@ import (
)
type (
Blog struct {
Title string `db:"title"`
Description string `db:"description"`
Visible bool `db:"visible"`
Date time.Time `db:"date"`
AuthorID string `db:"author"`
Markdown string `db:"markdown"`
HTML template.HTML `db:"html"`
BlueskyActorID string `db:"bsky_actor"`
BlueskyPostID string `db:"bsky_post"`
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 *Blog) TitleNormalised() string {
func (b *BlogPost) TitleNormalised() string {
rgx := regexp.MustCompile(`[^a-z0-9\-]`)
return rgx.ReplaceAllString(
strings.ReplaceAll(
@ -32,10 +35,17 @@ func (b *Blog) TitleNormalised() string {
)
}
func (b *Blog) GetMonth() string {
return fmt.Sprintf("%02d", int(b.Date.Month()))
func (b *BlogPost) GetMonth() string {
return fmt.Sprintf("%02d", int(b.CreatedAt.Month()))
}
func (b *Blog) PrintDate() string {
return b.Date.Format("02 January 2006")
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")
}

View file

@ -55,7 +55,7 @@ type (
func (record *Record) CreatedAtPrint() (string, error) {
t, err := record.CreatedAtTime()
if err != nil { return "", err }
return t.Format("15:04, 2 February 2006"), nil
return t.Format("2 Jan 2006, 15:04"), nil
}
func (record *Record) CreatedAtTime() (time.Time, error) {