aboutsummaryrefslogtreecommitdiffstats
path: root/site.go
diff options
context:
space:
mode:
Diffstat (limited to 'site.go')
-rw-r--r--site.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/site.go b/site.go
new file mode 100644
index 0000000..8a9f08d
--- /dev/null
+++ b/site.go
@@ -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)
+ }
+ }
+}