diff options
author | Noah Campbell <noahcampbell@gmail.com> | 2013-10-01 12:51:00 -0700 |
---|---|---|
committer | Noah Campbell <noahcampbell@gmail.com> | 2013-10-08 18:37:49 +0200 |
commit | 03d1a57fea650c13f7ca05481f5c84ffabeb2757 (patch) | |
tree | 27472cf812490c0b0d13b055a60c66bdf5d3d733 /transform | |
parent | 5e14af957a5167770e8498df6ea356326aae3b0b (diff) |
Set the name of the Nav attribute to select
Diffstat (limited to 'transform')
-rw-r--r-- | transform/nav.go | 7 | ||||
-rw-r--r-- | transform/nav_test.go | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/transform/nav.go b/transform/nav.go index c3dfe7900..b085c39a2 100644 --- a/transform/nav.go +++ b/transform/nav.go @@ -8,6 +8,7 @@ import ( type NavActive struct { Section string + AttrName string } func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) { @@ -22,7 +23,11 @@ func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) { return } - tr.Apply(htmltran.ModifyAttrib("class", "active"), fmt.Sprintf("li[data-nav=%s]", n.Section)) + 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) } diff --git a/transform/nav_test.go b/transform/nav_test.go index 997fe33f6..78e00f7df 100644 --- a/transform/nav_test.go +++ b/transform/nav_test.go @@ -12,8 +12,8 @@ const HTML_WITH_NAV = `<!DOCTYPE html> <body> <nav> <ul class="nav navbar-nav"> - <li data-nav="section_1"><a href="#">Section 1</a></li> - <li data-nav="section_2"><a href="#">Section 2</a></li> + <li hugo-nav="section_1"><a href="#">Section 1</a></li> + <li hugo-nav="section_2"><a href="#">Section 2</a></li> </ul> </nav> </body> @@ -23,8 +23,8 @@ const EXPECTED_HTML_WITH_NAV_1 = `<!DOCTYPE html><html><head></head> <body> <nav> <ul class="nav navbar-nav"> - <li data-nav="section_1"><a href="#">Section 1</a></li> - <li data-nav="section_2" class="active"><a href="#">Section 2</a></li> + <li hugo-nav="section_1"><a href="#">Section 1</a></li> + <li hugo-nav="section_2" class="active"><a href="#">Section 2</a></li> </ul> </nav> |