github.com/taubyte/tau-cli@v0.1.13-0.20240326000942-487f0d57edfc/singletons/templates/websites.go (about) 1 package templates 2 3 import ( 4 "os" 5 "path" 6 7 "gopkg.in/yaml.v3" 8 ) 9 10 func (t *templates) Websites() (map[string]TemplateInfo, error) { 11 return t.genericRepositoryTemplates(templateWebsiteFolder) 12 } 13 14 func (t *templates) Libraries() (map[string]TemplateInfo, error) { 15 return t.genericRepositoryTemplates(templateLibraryFolder) 16 } 17 18 func (t *templates) genericRepositoryTemplates(folder string) (map[string]TemplateInfo, error) { 19 templates, err := os.ReadDir(folder) 20 if err != nil { 21 return nil, err 22 } 23 24 templateMap := make(map[string]TemplateInfo, len(templates)) 25 for _, template := range templates { 26 templateDir := path.Join(folder, template.Name()) 27 28 yamlData, err := os.ReadFile(path.Join(templateDir, "config.yaml")) 29 if err != nil { 30 return nil, err 31 } 32 33 var _yaml templateYaml 34 err = yaml.Unmarshal(yamlData, &_yaml) 35 if err != nil { 36 return nil, err 37 } 38 39 // TODO Update website template description style 40 // description, err := os.ReadFile(path.Join(templateDir, "description.md")) 41 // if err != nil { 42 // return nil, err 43 // } 44 45 // stringDescription := string(description) 46 47 // // remove trailing newlines 48 // for { 49 // if len(stringDescription) == 0 { 50 // break 51 // } 52 53 // if stringDescription[len(stringDescription)-1] == '\n' { 54 // stringDescription = stringDescription[:len(stringDescription)-1] 55 // } else { 56 // break 57 // } 58 // } 59 60 templateMap[_yaml.Name] = TemplateInfo{ 61 URL: _yaml.URL, 62 // Description: stringDescription, 63 } 64 } 65 66 return templateMap, nil 67 }