blob: 2111ae89a0bd466696a6bf74ae453697ac92664a (
plain)
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
|
package transform
import (
htmltran "code.google.com/p/go-html-transform/html/transform"
"fmt"
"io"
)
type NavActive struct {
Section string
AttrName string
}
func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) {
var tr *htmltran.Transformer
if n.Section == "" {
_, err = io.Copy(w, r)
return
}
if tr, err = htmltran.NewFromReader(r); err != nil {
return
}
if n.AttrName == "" {
n.AttrName = "hugo-nav"
}
err = tr.Apply(htmltran.ModifyAttrib("class", "active"), fmt.Sprintf("li[%s=%s]", n.AttrName, n.Section))
if err != nil {
return
}
return tr.Render(w)
}
|