Nested chapter list

This commit is contained in:
Las Zenow 2012-08-28 11:50:08 +02:00
parent 5b4e0fb02e
commit de721f5ff3
2 changed files with 21 additions and 3 deletions

View file

@ -16,6 +16,8 @@ type chapter struct {
Link string
Depth int
Active bool
In bool // one level in depth
Out bool // one level out depth
}
type readData struct {
@ -78,15 +80,24 @@ func chapterList(e *epub.Epub, file string, id string, base string) (string, str
defer tit.Close()
activeIndx := -1
depth := 0
for ; tit.Valid(); tit.Next() {
var c chapter
c.Label = tit.Label()
c.Link = genLink(id, base, tit.Link())
c.Depth = tit.Depth()
if cleanLink(tit.Link()) == file {
c.Active = true
activeIndx = len(chapters)
}
c.Depth = tit.Depth()
if c.Depth > depth {
c.In = true
depth = c.Depth
}
if c.Depth < depth {
c.Out = true
depth = c.Depth
}
chapters = append(chapters, c)
}

View file

@ -18,11 +18,18 @@
<div class="row">
<div class="span4">
<ul class="nav nav-pills nav-stacked">
{{range .Chapters}}
<li {{if .Active}}class="active"{{end}}><a href="{{.Link}}">{{.Label}}</a></li>
{{if .In}}
<ul class="nav nav-list">
{{end}}
<li {{if .Active}}class="active"{{end}}><a href="{{.Link}}">{{.Label}}</a></li>
{{if .Out}}
</ul>
{{end}}
{{end}}
{{if .Chapters}}
</ul>
{{end}}
</div>
<div class="span8">