mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
80009b427f
Typically the destination is on the left and the src is on the right.
36 lines
605 B
Go
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)
|
|
}
|