-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProjectParser.go
53 lines (49 loc) · 1.45 KB
/
ProjectParser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Project struct {
ParentProjectMetadataPath string `yaml:"parent_project_metadata_path"`
Name string `yaml:"name"`
Description string `yaml:"description"`
HomeURL string `yaml:"home_url"`
Color string `yaml:"color"`
ContentLicense string `yaml:"content_license"`
FooterPath string `yaml:"footer_path"`
GoogleAnalyticsIds []string `yaml:"google_analytics_ids"`
Icon struct {
Path string `yaml:"path"`
} `yaml:"icon"`
SocialMedia struct {
Image struct {
Path string `yaml:"path"`
Width int `yaml:"width"`
Height int `yaml:"height"`
} `yaml:"image"`
} `yaml:"social_media"`
}
func ParseProject(filepath string) (*Project, *Project, error) {
projectContent, err := ioutil.ReadFile(flagSitePath + filepath)
if err != nil {
return nil, nil, err
}
project := Project{}
err = yaml.Unmarshal(projectContent, &project)
if err != nil {
return nil, nil, err
}
if project.ParentProjectMetadataPath == "" {
return &project, nil, nil
}
parentProjectContent, err := ioutil.ReadFile(flagSitePath + project.ParentProjectMetadataPath)
if err != nil {
return nil, nil, err
}
parentProject := Project{}
err = yaml.Unmarshal(parentProjectContent, &parentProject)
if err != nil {
return nil, nil, err
}
return &project, &parentProject, nil
}