Nested chapter list
This commit is contained in:
parent
5b4e0fb02e
commit
de721f5ff3
2 changed files with 21 additions and 3 deletions
13
reader.go
13
reader.go
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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">
|
||||
|
|
Reference in a new issue