diff options
Diffstat (limited to 'pkg/types/index.go')
| -rw-r--r-- | pkg/types/index.go | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/pkg/types/index.go b/pkg/types/index.go index f58d5f2..623555c 100644 --- a/pkg/types/index.go +++ b/pkg/types/index.go @@ -1,6 +1,11 @@ package types -import "sync" +import ( + "go.nc0.fr/svgu/pkg/templates" + "os" + "path" + "sync" +) // Index is the global object representing the Starlark configuration. type Index struct { @@ -45,3 +50,31 @@ func (i *Index) CheckModule(n string) bool { _, ok := i.Modules[n] return ok } + +// GenerateFile generates the index file. +func (i *Index) GenerateFile(out string) error { + i.lock.Lock() + defer i.lock.Unlock() + + f := path.Join(out, "index.html") + + // Create the file. + fd, err := os.Create(f) + if err != nil { + return err + } + defer func(fd *os.File) { + err := fd.Close() + if err != nil { + panic(err) + } + }(fd) + + // Execute the template and write the output to the file. + if err := templates.ExecIndex(fd, + "https://pkg.go.dev", 2); err != nil { + return err + } + + return nil +} |
