Add model
This commit is contained in:
parent
25bd66be5e
commit
dc7c2e1abd
15
cli/cli.go
15
cli/cli.go
|
@ -5,23 +5,28 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
|
|
||||||
"git.rdelaage.ovh/rdelaage/cyanocorax/version"
|
"git.rdelaage.ovh/rdelaage/cyanocorax/version"
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/manage"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagInfoHelp = "Show application information"
|
flagInfoHelp = "Show application information"
|
||||||
flagVersionHelp = "Show application version"
|
flagVersionHelp = "Show application version"
|
||||||
|
flagSiteHelp = "Set site file path"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Parse() {
|
func Parse() {
|
||||||
var (
|
var (
|
||||||
flagInfo bool
|
flagInfo bool
|
||||||
flagVersion bool
|
flagVersion bool
|
||||||
|
flagSite string
|
||||||
)
|
)
|
||||||
|
|
||||||
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
|
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
|
||||||
flag.BoolVar(&flagInfo, "i", false, flagInfoHelp)
|
flag.BoolVar(&flagInfo, "i", false, flagInfoHelp)
|
||||||
flag.BoolVar(&flagVersion, "version", false, flagVersionHelp)
|
flag.BoolVar(&flagVersion, "version", false, flagVersionHelp)
|
||||||
flag.BoolVar(&flagVersion, "v", false, flagVersionHelp)
|
flag.BoolVar(&flagVersion, "v", false, flagVersionHelp)
|
||||||
|
flag.StringVar(&flagSite, "site", "", flagSiteHelp)
|
||||||
|
flag.StringVar(&flagSite, "s", "", flagSiteHelp)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -34,4 +39,10 @@ func Parse() {
|
||||||
fmt.Println(version.Version)
|
fmt.Println(version.Version)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if flagSite == "" {
|
||||||
|
fmt.Println("Flag site must be set")
|
||||||
|
} else {
|
||||||
|
fmt.Println(manage.SiteFromFile(flagSite))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package manage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/model/site"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SiteFromFile(filePath string) (site.Site, error) {
|
||||||
|
var site site.Site
|
||||||
|
|
||||||
|
file, err := os.ReadFile(filePath)
|
||||||
|
if err != nil {
|
||||||
|
return site, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal(file, &site)
|
||||||
|
if err != nil {
|
||||||
|
return site, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return site, err
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package author
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Author struct {
|
||||||
|
Handle string `json:"handle"`
|
||||||
|
FullName string `json:"fullName"`
|
||||||
|
Bio []string `json:"bio"`
|
||||||
|
Banner []string `json:"banner"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Author) GetBio() string {
|
||||||
|
return strings.Join(a.Bio, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Author) SetBio(newBio string) {
|
||||||
|
a.Bio = strings.Split(newBio, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Author) GetBanner() string {
|
||||||
|
return strings.Join(a.Banner, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *Author) SetBanner(newBanner string) {
|
||||||
|
a.Banner = strings.Split(newBanner, "\n")
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package page
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Page struct {
|
||||||
|
Title string `json:"title"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Content []string `json:"content"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) GetPage() string {
|
||||||
|
return strings.Join(p.Content, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Page) SetPage(newContent string) {
|
||||||
|
p.Content = strings.Split(newContent, "\n")
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package post
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/model/page"
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/model/tag"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Post struct {
|
||||||
|
page.Page
|
||||||
|
|
||||||
|
authors []string `json:"authors"`
|
||||||
|
tags []tag.Tag `json:"tags"`
|
||||||
|
dateEdit time.Time `json:"dateEdit"`
|
||||||
|
dateCreate time.Time `json:"dateCreate"`
|
||||||
|
datePublish time.Time `json:"datePublish"`
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package site
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/model/author"
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/model/post"
|
||||||
|
"git.rdelaage.ovh/rdelaage/cyanocorax/model/page"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Site struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
Authors []author.Author `json:"authors"`
|
||||||
|
Posts []post.Post `json:"posts"`
|
||||||
|
Pages []page.Page `json:"pages"`
|
||||||
|
Abstract []string `json:"abstract"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Site) GetAbstract() string {
|
||||||
|
return strings.Join(s.Abstract, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Site) SetAbstract(newAbstract string) {
|
||||||
|
s.Abstract = strings.Split(newAbstract, "\n")
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package tag
|
||||||
|
|
||||||
|
type Tag struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
Loading…
Reference in New Issue