aboutsummaryrefslogtreecommitdiffstats
path: root/site.go
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2020-02-01 15:55:15 +0100
committerEddy Pedroni <eddy@0xf7.com>2020-02-01 15:55:15 +0100
commited306e653641769ffb8d084ea7717f18a5a9239c (patch)
treebdf8d7e47566741584fc81800f853b54cbda3021 /site.go
parentc1d6f344316789c560107777d9d332c9a8f15bd3 (diff)
Refactored, all sites are generated now
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)
+ }
+ }
+}