-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.go
41 lines (34 loc) · 917 Bytes
/
generate.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
package main
import (
"html/template"
"os"
"path/filepath"
)
// PackageInfo contains information required for the package template
type PackageInfo struct {
Name string
Repo string
CanonicalURL string
GodocURL string
}
// generateSite creates a directory and index.html files per PackageInfo item
func generateSite(packageInfoSlice []PackageInfo, outputDirectory string, indexTemplate *template.Template) error {
for _, packageInfo := range packageInfoSlice {
var (
err error
outputDir = filepath.Join(outputDirectory, packageInfo.Name)
fileName = filepath.Join(outputDir + "/index.html")
file *os.File
)
if err = os.MkdirAll(outputDir, os.ModePerm); err != nil {
return err
}
if file, err = os.Create(fileName); err != nil {
return err
}
if err = indexTemplate.Execute(file, packageInfo); err != nil {
return err
}
}
return nil
}