hugo/transform/nav.go
Noah Campbell 80009b427f Change the order of Apply to be more Unixy
Typically the destination is on the left and the src is on the right.
2013-10-08 18:37:50 +02:00

36 lines
605 B
Go

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(w io.Writer, r io.Reader) (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)
}