basic blog page!
This commit is contained in:
parent
8eb432539c
commit
1a8dc4d9ce
9 changed files with 209 additions and 0 deletions
39
model/blog.go
Normal file
39
model/blog.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue