diff --git a/cli/cli.go b/cli/cli.go index fe84800..6149d97 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -5,23 +5,28 @@ import ( "flag" "git.rdelaage.ovh/rdelaage/cyanocorax/version" + "git.rdelaage.ovh/rdelaage/cyanocorax/manage" ) const ( - flagInfoHelp = "Show application information" + flagInfoHelp = "Show application information" flagVersionHelp = "Show application version" + flagSiteHelp = "Set site file path" ) func Parse() { var ( - flagInfo bool + flagInfo bool flagVersion bool + flagSite string ) flag.BoolVar(&flagInfo, "info", false, flagInfoHelp) flag.BoolVar(&flagInfo, "i", false, flagInfoHelp) flag.BoolVar(&flagVersion, "version", false, flagVersionHelp) flag.BoolVar(&flagVersion, "v", false, flagVersionHelp) + flag.StringVar(&flagSite, "site", "", flagSiteHelp) + flag.StringVar(&flagSite, "s", "", flagSiteHelp) flag.Parse() @@ -34,4 +39,10 @@ func Parse() { fmt.Println(version.Version) return } + + if flagSite == "" { + fmt.Println("Flag site must be set") + } else { + fmt.Println(manage.SiteFromFile(flagSite)) + } } diff --git a/manage/site.go b/manage/site.go new file mode 100644 index 0000000..8216c17 --- /dev/null +++ b/manage/site.go @@ -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 +} diff --git a/model/author/author.go b/model/author/author.go new file mode 100644 index 0000000..ce7d389 --- /dev/null +++ b/model/author/author.go @@ -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") +} diff --git a/model/page/page.go b/model/page/page.go new file mode 100644 index 0000000..523a00b --- /dev/null +++ b/model/page/page.go @@ -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") +} diff --git a/model/post/post.go b/model/post/post.go new file mode 100644 index 0000000..ce86b38 --- /dev/null +++ b/model/post/post.go @@ -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"` +} diff --git a/model/site/site.go b/model/site/site.go new file mode 100644 index 0000000..57f05eb --- /dev/null +++ b/model/site/site.go @@ -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") +} diff --git a/model/tag/tag.go b/model/tag/tag.go new file mode 100644 index 0000000..b2662ba --- /dev/null +++ b/model/tag/tag.go @@ -0,0 +1,5 @@ +package tag + +type Tag struct { + Name string `json:"name"` +}