diff options
Diffstat (limited to 'site.go')
-rw-r--r-- | site.go | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -0,0 +1,51 @@ +package main + +import ( + "io/ioutil" + "path/filepath" +) + +type siteData struct { + name string + rawName string + baseUrl string + outputPath string + sourcePath string + pages map[string]page + nav []navItem +} + +func getSites(cfg config) (sites []siteData) { + files, err := ioutil.ReadDir(cfg.DocsRoot) + if err != nil { + panic(err) + } + + for _, f := range files { + if f.IsDir() && f.Name() != ".git" { + newSite := siteData{ + name: nameify(f.Name()), + rawName: f.Name(), + baseUrl: filepath.Join(cfg.BaseUrl, f.Name()), + outputPath: filepath.Join(cfg.TargetDir, f.Name()), + sourcePath: filepath.Join(cfg.DocsRoot, f.Name())} + sites = append(sites, newSite) + } + } + + return +} + +func generateSite(site siteData, cfg config) { + template := loadTemplate(cfg) + templData := templateData{SiteTitle: site.name, + StylesheetUrl: cfg.CssFile, + Nav: site.nav} + for k, v := range site.pages { + templData.Content = v.content + err := applyTemplate(filepath.Join(site.outputPath, k), templData, template) + if err != nil { + panic(err) + } + } +} |