mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	Set the name of the Nav attribute to select
This commit is contained in:
		| @@ -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) | ||||
| } | ||||
|   | ||||
| @@ -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> | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user