aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main.go18
-rw-r--r--site.go13
-rw-r--r--utils.go19
3 files changed, 40 insertions, 10 deletions
diff --git a/main.go b/main.go
index 075caa4..870e0f9 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,9 @@ package main
import (
"fmt"
+ "github.com/otiai10/copy"
"os"
+ "path/filepath"
)
func main() {
@@ -13,10 +15,10 @@ func main() {
}
// read config file specified in the command line
- cfg, err := readConfig(os.Args[1])
- if err != nil {
- panic(err)
- }
+ cfg := readConfig(os.Args[1])
+
+ // create temporary target directory
+ tmp := createTempDir("godocs")
// gather all sites in docsRoot
sites := getSites(cfg)
@@ -32,6 +34,12 @@ func main() {
createNavSlice(&site, cfg)
// output the site
- generateSite(site, cfg)
+ generateSite(site, cfg, tmp)
+ }
+
+ // copy CSS file to generation directory
+ err := copy.Copy(cfg.CssFile, filepath.Join(tmp, "style.css"))
+ if err != nil {
+ panic(err)
}
}
diff --git a/site.go b/site.go
index 4050bf0..1d0358f 100644
--- a/site.go
+++ b/site.go
@@ -2,6 +2,7 @@ package main
import (
"io/ioutil"
+ "os"
"path/filepath"
)
@@ -36,16 +37,22 @@ func getSites(cfg config) (sites []siteData) {
return
}
-func generateSite(site siteData, cfg config) {
+func generateSite(site siteData, cfg config, outputDir string) {
template := loadTemplate(cfg)
templData := templateData{SiteTitle: site.name,
- StylesheetUrl: cfg.CssFile,
+ StylesheetUrl: cfg.BaseUrl + "/style.css",
Nav: site.nav}
for k, v := range site.pages {
templData.Content = v.content
- err := applyTemplate(filepath.Join(site.outputPath, k), templData, template)
+ err := applyTemplate(filepath.Join(outputDir, site.rawName, k), templData, template)
if err != nil {
panic(err)
}
}
+
+ // link images to generation directory
+ err := os.Symlink(filepath.Join(site.sourcePath, "img"), filepath.Join(outputDir, site.rawName, "img"))
+ if err != nil {
+ panic(err)
+ }
}
diff --git a/utils.go b/utils.go
index 42780c4..db36745 100644
--- a/utils.go
+++ b/utils.go
@@ -2,6 +2,8 @@ package main
import (
"github.com/BurntSushi/toml"
+ "io/ioutil"
+ "os"
"strings"
)
@@ -13,8 +15,11 @@ type config struct {
BaseUrl string
}
-func readConfig(file string) (cfg config, err error) {
- _, err = toml.DecodeFile(file, &cfg)
+func readConfig(file string) (cfg config) {
+ _, err := toml.DecodeFile(file, &cfg)
+ if err != nil {
+ panic(err)
+ }
cfg.BaseUrl = strings.TrimSuffix(cfg.BaseUrl, "/")
return
}
@@ -25,3 +30,13 @@ func nameify(raw string) (clean string) {
clean = strings.Title(clean)
return
}
+
+func createTempDir(name string) (path string) {
+ path, err := ioutil.TempDir("", "godocs")
+ if err != nil {
+ panic(err)
+ }
+ defer os.RemoveAll(path)
+
+ return
+}