mirror of
https://github.com/gohugoio/hugo.git
synced 2025-02-23 15:13:04 +00:00
33 lines
569 B
Go
33 lines
569 B
Go
package transform
|
|
|
|
import (
|
|
htmltran "code.google.com/p/go-html-transform/html/transform"
|
|
"io"
|
|
"fmt"
|
|
)
|
|
|
|
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"
|
|
}
|
|
|
|
tr.Apply(htmltran.ModifyAttrib("class", "active"), fmt.Sprintf("li[%s=%s]", n.AttrName, n.Section))
|
|
|
|
return tr.Render(w)
|
|
}
|