mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
5a66fa3954
Transformers can now be chained together, working on the output of the previous run.
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(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)
|
|
}
|