@@ -9,16 +9,20 @@ import (
99 "strings"
1010
1111 "github.com/evcc-io/evcc/util/templates"
12+ "github.com/gosimple/slug"
1213)
1314
1415const (
1516 docsPath = "../../../templates/docs"
1617 websitePath = "../../../templates/evcc.io"
18+ iconsPath = "../../../templates/icons"
1719)
1820
1921//go:generate go run main.go
2022
2123func main () {
24+ slug .CustomSub = map [string ]string {"+" : "plus" }
25+
2226 for _ , lang := range []string {"de" , "en" } {
2327 if err := generateDocs (lang ); err != nil {
2428 panic (err )
@@ -28,6 +32,10 @@ func main() {
2832 if err := generateBrandJSON (); err != nil {
2933 panic (err )
3034 }
35+
36+ if err := generateProductJSON (); err != nil {
37+ panic (err )
38+ }
3139}
3240
3341func generateDocs (lang string ) error {
@@ -57,15 +65,20 @@ func generateClass(class templates.Class, lang string) error {
5765 return err
5866 }
5967
60- for index , product := range tmpl .Products {
68+ for _ , product := range tmpl .Products {
6169 fmt .Println (tmpl .Template + ": " + product .Title (lang ))
6270
6371 b , err := tmpl .RenderDocumentation (product , lang )
6472 if err != nil {
6573 return err
6674 }
6775
68- filename := fmt .Sprintf ("%s/%s/%s/%s_%d.yaml" , docsPath , lang , strings .ToLower (class .String ()), tmpl .Template , index )
76+ filename := fmt .Sprintf ("%s/%s/%s/%s.yaml" , docsPath , lang , strings .ToLower (class .String ()), product .Identifier ())
77+
78+ if _ , err := os .Stat (filename ); err == nil {
79+ return fmt .Errorf ("file already exists: %s - product titles must be unique" , filename )
80+ }
81+
6982 if err := os .WriteFile (filename , b , 0o644 ); err != nil {
7083 return err
7184 }
@@ -164,3 +177,39 @@ func generateBrandJSON() error {
164177
165178 return err
166179}
180+
181+ func generateProductJSON () error {
182+ type ProductInfo struct {
183+ Brand string `json:"brand"`
184+ Description string `json:"description"`
185+ }
186+
187+ products := make (map [string ]map [string ]ProductInfo )
188+
189+ for _ , class := range templates .ClassValues () {
190+ classKey := strings .ToLower (class .String ())
191+ products [classKey ] = make (map [string ]ProductInfo )
192+
193+ for _ , tmpl := range templates .ByClass (class ) {
194+ for _ , product := range tmpl .Products {
195+ products [classKey ][product .Identifier ()] = ProductInfo {
196+ Brand : product .Brand ,
197+ Description : product .Description .String ("en" ),
198+ }
199+ }
200+ }
201+ }
202+
203+ if _ , err := os .Stat (iconsPath ); os .IsNotExist (err ) {
204+ if err := os .MkdirAll (iconsPath , 0o755 ); err != nil {
205+ return err
206+ }
207+ }
208+
209+ file , err := json .MarshalIndent (products , "" , " " )
210+ if err == nil {
211+ err = os .WriteFile (iconsPath + "/products.json" , file , 0o644 )
212+ }
213+
214+ return err
215+ }
0 commit comments