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
|
Link string
|
||||||
Depth int
|
Depth int
|
||||||
Active bool
|
Active bool
|
||||||
|
In bool // one level in depth
|
||||||
|
Out bool // one level out depth
|
||||||
}
|
}
|
||||||
|
|
||||||
type readData struct {
|
type readData struct {
|
||||||
|
@ -78,15 +80,24 @@ func chapterList(e *epub.Epub, file string, id string, base string) (string, str
|
||||||
defer tit.Close()
|
defer tit.Close()
|
||||||
|
|
||||||
activeIndx := -1
|
activeIndx := -1
|
||||||
|
depth := 0
|
||||||
for ; tit.Valid(); tit.Next() {
|
for ; tit.Valid(); tit.Next() {
|
||||||
var c chapter
|
var c chapter
|
||||||
c.Label = tit.Label()
|
c.Label = tit.Label()
|
||||||
c.Link = genLink(id, base, tit.Link())
|
c.Link = genLink(id, base, tit.Link())
|
||||||
c.Depth = tit.Depth()
|
|
||||||
if cleanLink(tit.Link()) == file {
|
if cleanLink(tit.Link()) == file {
|
||||||
c.Active = true
|
c.Active = true
|
||||||
activeIndx = len(chapters)
|
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)
|
chapters = append(chapters, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,11 +18,18 @@
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span4">
|
<div class="span4">
|
||||||
<ul class="nav nav-pills nav-stacked">
|
|
||||||
{{range .Chapters}}
|
{{range .Chapters}}
|
||||||
<li {{if .Active}}class="active"{{end}}><a href="{{.Link}}">{{.Label}}</a></li>
|
{{if .In}}
|
||||||
|
<ul class="nav nav-list">
|
||||||
{{end}}
|
{{end}}
|
||||||
|
<li {{if .Active}}class="active"{{end}}><a href="{{.Link}}">{{.Label}}</a></li>
|
||||||
|
{{if .Out}}
|
||||||
</ul>
|
</ul>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
{{if .Chapters}}
|
||||||
|
</ul>
|
||||||
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="span8">
|
<div class="span8">
|
||||||
|
|
Reference in a new issue