40 lines
713 B
Go
40 lines
713 B
Go
|
package model
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"html/template"
|
||
|
"regexp"
|
||
|
"strings"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
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"`
|
||
|
}
|
||
|
)
|
||
|
|
||
|
func (b *Blog) TitleNormalised() string {
|
||
|
rgx := regexp.MustCompile(`[^a-z0-9\-]`)
|
||
|
return rgx.ReplaceAllString(
|
||
|
strings.ReplaceAll(
|
||
|
strings.ToLower(b.Title), " ", "-",
|
||
|
),
|
||
|
"",
|
||
|
)
|
||
|
}
|
||
|
|
||
|
func (b *Blog) GetMonth() string {
|
||
|
return fmt.Sprintf("%02d", int(b.Date.Month()))
|
||
|
}
|
||
|
|
||
|
func (b *Blog) PrintDate() string {
|
||
|
return b.Date.Format("02 January 2006")
|
||
|
}
|