diff --git a/main.go b/main.go
index 08e60ce..ea144d3 100644
--- a/main.go
+++ b/main.go
@@ -23,14 +23,14 @@ type Node struct {
Data NodeData
}
-func (n Node) writeHTML(w io.Writer) {
+func (n *Node) writeIndex(w io.Writer) {
tmpl, err := template.New("root").Parse(`
{{ define "tree" }}
{{ if gt (len .Children) 0 }}
{{ range $index, $element := .Children}}
-
- {{ $element.Data.Title }}
+ {{ $element.Data.Title }}
{{ template "tree" $element }}
{{ end }}
@@ -50,6 +50,17 @@ func (n Node) writeHTML(w io.Writer) {
}
}
+func (n *Node) writeHTMLFiles() {
+ if len(n.Children) > 0 {
+ for _, child := range n.Children {
+ writeHTML(n)
+ child.writeHTMLFiles()
+ }
+ }
+ // leaf node
+ writeHTML(n)
+}
+
func (n *Node) getChildWithID(id string) (node *Node, hasChild bool) {
for _, c := range n.Children {
if c.Data.Id == id {
@@ -64,6 +75,15 @@ func (n *Node) addChild(child *Node) {
n.Children = append(n.Children, child)
}
+func writeHTML(n *Node) {
+ 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()
+ f.Write([]byte(n.Data.Title))
+}
+
type spaceResult struct {
Results []struct {
ID string `json:"id"`
@@ -191,13 +211,14 @@ func createPageTree(s *spaceResult) {
n := Node{Data: NodeData{Id: page.ID, Title: page.Title}}
parent.addChild(&n)
}
- fname := "tree.html"
+ fname := "index.html"
f, err := os.Create(fname)
if err != nil {
log.Fatalf("Failed to open %v", fname)
}
defer f.Close()
- root.writeHTML(f)
+ root.writeIndex(f)
+ root.writeHTMLFiles()
}
func main() {