mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Set the name of the Nav attribute to select
This commit is contained in:
parent
5e14af957a
commit
03d1a57fea
2 changed files with 10 additions and 5 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
type NavActive struct {
|
type NavActive struct {
|
||||||
Section string
|
Section string
|
||||||
|
AttrName string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) {
|
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
|
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)
|
return tr.Render(w)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ const HTML_WITH_NAV = `<!DOCTYPE html>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li data-nav="section_1"><a href="#">Section 1</a></li>
|
<li hugo-nav="section_1"><a href="#">Section 1</a></li>
|
||||||
<li data-nav="section_2"><a href="#">Section 2</a></li>
|
<li hugo-nav="section_2"><a href="#">Section 2</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</body>
|
</body>
|
||||||
|
@ -23,8 +23,8 @@ const EXPECTED_HTML_WITH_NAV_1 = `<!DOCTYPE html><html><head></head>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li data-nav="section_1"><a href="#">Section 1</a></li>
|
<li hugo-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_2" class="active"><a href="#">Section 2</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue