Calculate the depth on the chapters properly

This commit is contained in:
Las Zenow 2014-08-28 23:54:15 -05:00
parent 0cbda42c58
commit e81df155a2

View file

@ -4,15 +4,16 @@ import log "github.com/cihub/seelog"
import ( import (
"bytes" "bytes"
"git.gitorious.org/go-pkg/epubgo.git"
"git.gitorious.org/trantor/trantor.git/database"
"git.gitorious.org/trantor/trantor.git/storage"
"github.com/gorilla/mux"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"git.gitorious.org/go-pkg/epubgo.git"
"git.gitorious.org/trantor/trantor.git/database"
"git.gitorious.org/trantor/trantor.git/storage"
"github.com/gorilla/mux"
) )
type chapter struct { type chapter struct {
@ -113,24 +114,18 @@ func listChapters(nav *epubgo.NavigationIterator, depth int) []chapter {
c.Label = nav.Title() c.Label = nav.Title()
c.Link = nav.URL() c.Link = nav.URL()
c.Depth = depth c.Depth = depth
for c.Depth < depth {
c.Out = append(c.Out, true)
depth--
}
chapters = append(chapters, c) chapters = append(chapters, c)
if nav.HasChildren() { if nav.HasChildren() {
nav.In() nav.In()
children := listChapters(nav, depth+1) children := listChapters(nav, depth+1)
children[0].In = []bool{true}
children[len(children)-1].Out = []bool{true}
chapters = append(chapters, children...) chapters = append(chapters, children...)
nav.Out() nav.Out()
} }
err = nav.Next() err = nav.Next()
} }
chapters[0].In = []bool{true} chapters[0].In = append(chapters[0].In, true)
chapters[len(chapters)-1].Out = []bool{true} chapters[len(chapters)-1].Out = append(chapters[len(chapters)-1].Out, true)
return chapters return chapters
} }