-
Notifications
You must be signed in to change notification settings - Fork 1
/
toc.go
94 lines (91 loc) · 2.26 KB
/
toc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"github.com/badgerodon/go/dom"
"github.com/badgerodon/go/dom/css"
. "github.com/badgerodon/go/dom/dsl"
)
func (this *Generator) GetTOC() dom.Node {
headings := make([]Heading, 0)
for _, h := range css.Find(this.output, "h1, h2") {
lvl := 0
if e, ok := h.(*dom.Element); ok {
if e.Tag == "h2" {
lvl = 1
}
}
headings = append(headings, Heading{lvl, dom.TextContent(h)})
}
ol := E("ol", A("id", "toc"))
var h1 dom.Node = F()
h1c := 0
h2c := 1
for _, h := range headings {
if h.level == 0 {
h1c++
h1 = E("ol")
ol.Append(
E("li",
E("a", A("href", fmt.Sprint(h1c)),
h.text,
),
h1,
),
)
h2c = 1
}
if h.level == 1 {
h1.Append(
E("li",
E("a", A("href", fmt.Sprint(h1c, "#section", h2c)),
h.text,
),
),
)
h2c++
}
}
return F(
E("h1", A("class", "title"), "An Introduction to Programming in Go"),
E("img", A("src", "assets/img/cover.png"), A("class", "block"), A("title", "Cover")),
E("h2", "Installers"),
E("p", "Installs Go and a text editor.",
E("ul",
E("li",
E("a", A("href", "/installers/go-install.exe"), "Windows"),
),
E("li",
"OSX (",
E("a", A("href", "/installers/go-install-x86.pkg"), "32 bit"),
", ",
E("a", A("href", "/installers/go-install-x64.pkg"), "64 bit"),
")",
),
),
),
E("h2", "The Book"),
E("p",
E("i",
"An Introduction to Programming in Go",
), ".", E("br"),
"Copyright ", H("©"), " 2012 by Caleb Doxsey", E("br"),
"ISBN: 978-1478355823",
),
E("p",
"This book is available for purchase at Amazon.com in ",
E("a", A("href", "http://www.amazon.com/An-Introduction-Programming-Go-ebook/dp/B0095MCNAO/"), "Kindle"),
" or ",
E("a", A("href", "http://www.amazon.com/An-Introduction-Programming-Caleb-Doxsey/dp/1478355824"), "Paperback"),
". It is available for free online below or in ",
E("a", A("href", "/assets/pdf/gobook.pdf"), "PDF form"),
".",
),
E("p",
"Questions, comments, corrections or concerns can be sent to ",
E("a", A("href", "mailto:[email protected]"), "Caleb Doxsey"),
".",
),
E("h2", "Table of Contents"),
ol,
)
}