From d291d281a2fe28e260592746f5f957f1b3c6994a Mon Sep 17 00:00:00 2001 From: Johannes Rothe Date: Mon, 12 Sep 2022 21:38:04 +0200 Subject: [PATCH] Put files in subdirectories, bootstrap css --- main.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 206d02d..5050dc6 100644 --- a/main.go +++ b/main.go @@ -38,15 +38,22 @@ func (n *Node) writeIndex(w io.Writer) { {{ end }} {{ end }} - - {{ template "tree" . }} + + + + + + + + {{ template "tree" . }} + `) if err != nil { @@ -84,13 +91,28 @@ func (n *Node) addChild(child *Node) { } func writeHTML(n *Node) { + os.Chdir("pages") f, err := os.Create(n.Data.Id + ".html") if err != nil { log.Fatalf("Error creating file for ID %v", n.Data.Id) } defer f.Close() - log.Printf("Writing file %v", f.Name()) - f.Write([]byte(n.Data.Body)) + log.Printf("Writing file %v containing page: %v", f.Name(), n.Data.Title) + html := ` + + + + + + + + ` + html += n.Data.Body + html += "" + _, err = f.Write([]byte(html)) + if err != nil { + log.Fatalf("Error writing file for ID %v", n.Data.Id) + } } type spaceResult struct { @@ -310,6 +332,9 @@ func main() { root := createPageTree(&result) fname := "index.html" + os.Mkdir("content", 0744) + os.Mkdir("content/pages", 0744) + os.Chdir("content") f, err := os.Create(fname) if err != nil { log.Fatalf("Failed to open %v", fname)