content/static/html/doc: group type and sub-items
Rewrite body.tmpl so that if a type is deprecated, its methods and
functions are hidden along with the type itself.
For golang/go#17056
Change-Id: I7ba11f0902414e25c6267747d1a68aa26751e95a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/315509
Trust: Jonathan Amsterdam <jba@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/content/static/html/doc/body.tmpl b/content/static/html/doc/body.tmpl
index b2ce25f..09900b6 100644
--- a/content/static/html/doc/body.tmpl
+++ b/content/static/html/doc/body.tmpl
@@ -117,29 +117,6 @@
{{- range .Types -}}
<div class="Documentation-type">
{{template "item" .}}
- {{- range .Consts -}}
- <div class="Documentation-typeConstant">
- {{- template "declaration" . -}}
- </div>
- {{- end -}}
-
- {{- range .Vars -}}
- <div class="Documentation-typeVariable">
- {{- template "declaration" . -}}
- </div>
- {{- end -}}
-
- {{- range .Funcs -}}
- <div class="Documentation-typeFunc">
- {{template "item" .}}
- </div>
- {{- end -}}
-
- {{- range .Methods -}}
- <div class="Documentation-typeMethod">
- {{template "item" .}}
- </div>
- {{- end -}}
</div>
{{- end -}}
{{- else -}}
@@ -178,15 +155,38 @@
{{- template "since_version" .FullName -}}
</h4>{{"\n"}}
</summary>
- {{- template "declaration" . -}}
- {{- template "example" .Examples -}}
+ {{template "item_body" .}}
</details>
{{else}}
<h4 tabindex="-1" id="{{$id}}" data-kind="{{.Kind}}" class="{{.HeaderClass}}">
<span>{{.HeaderStart}} {{source_link .Name .Decl}} <a class="Documentation-idLink" href="#{{$id}}">¶</a></span>
{{- template "since_version" .FullName -}}
</h4>{{"\n"}}
- {{- template "declaration" . -}}
- {{- template "example" .Examples -}}
+ {{template "item_body" .}}
{{end}}
{{end}}
+
+{{define "item_body"}}
+ {{- template "declaration" . -}}
+ {{- template "example" .Examples -}}
+ {{- range .Consts -}}
+ <div class="Documentation-typeConstant">
+ {{- template "declaration" . -}}
+ </div>
+ {{- end -}}
+ {{- range .Vars -}}
+ <div class="Documentation-typeVariable">
+ {{- template "declaration" . -}}
+ </div>
+ {{- end -}}
+ {{- range .Funcs -}}
+ <div class="Documentation-typeFunc">
+ {{template "item" .}}
+ </div>
+ {{- end -}}
+ {{- range .Methods -}}
+ <div class="Documentation-typeMethod">
+ {{template "item" .}}
+ </div>
+ {{- end -}}
+{{end}}
\ No newline at end of file
diff --git a/internal/godoc/dochtml/testdata/deprecated-off.golden b/internal/godoc/dochtml/testdata/deprecated-off.golden
index f7ba714..a442dca 100644
--- a/internal/godoc/dochtml/testdata/deprecated-off.golden
+++ b/internal/godoc/dochtml/testdata/deprecated-off.golden
@@ -14,6 +14,14 @@
<li class="Documentation-indexFunction">
<a href="#GoodF">func GoodF()</a></li>
<li class="Documentation-indexType"><a href="#BadT">type BadT</a></li>
+<li><ul class="Documentation-indexTypeFunctions">
+<li><a href="#NewBadTBad">func NewBadTBad() BadT</a></li>
+<li><a href="#NewBadTGood">func NewBadTGood() BadT</a></li>
+</ul></li>
+<li><ul class="Documentation-indexTypeMethods">
+<li><a href="#BadT.BadM">func (BadT) BadM()</a></li>
+<li><a href="#BadT.GoodM">func (BadT) GoodM()</a></li>
+</ul></li>
<li class="Documentation-indexType"><a href="#GoodT">type GoodT</a></li>
<li><ul class="Documentation-indexTypeFunctions">
<li><a href="#NewGoodTBad">func NewGoodTBad() GoodT</a></li>
@@ -96,6 +104,51 @@
Deprecated: use GoodT.
Don't use this.
</p>
+<div class="Documentation-typeFunc">
+<h4 tabindex="-1" id="NewBadTBad" data-kind="function" class="Documentation-typeFuncHeader">
+<span>func <a class="Documentation-source" href="src">NewBadTBad</a> <a class="Documentation-idLink" href="#NewBadTBad">¶</a></span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+<div class="Documentation-declaration">
+<pre>func NewBadTBad() <a href="#BadT">BadT</a></pre>
+</div>
+<div role="navigation" aria-label="Table of Contents">
+<ul class="Documentation-toc"></ul>
+</div><p>Deprecated: use NewBadTGood.
+</p>
+</div><div class="Documentation-typeFunc">
+<h4 tabindex="-1" id="NewBadTGood" data-kind="function" class="Documentation-typeFuncHeader">
+<span>func <a class="Documentation-source" href="src">NewBadTGood</a> <a class="Documentation-idLink" href="#NewBadTGood">¶</a></span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+<div class="Documentation-declaration">
+<pre>func NewBadTGood() <a href="#BadT">BadT</a></pre>
+</div>
+</div><div class="Documentation-typeMethod">
+<h4 tabindex="-1" id="BadT.BadM" data-kind="method" class="Documentation-typeMethodHeader">
+<span>func (BadT) <a class="Documentation-source" href="src">BadM</a> <a class="Documentation-idLink" href="#BadT.BadM">¶</a></span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+<div class="Documentation-declaration">
+<pre>func (<a href="#BadT">BadT</a>) BadM()</pre>
+</div>
+<div role="navigation" aria-label="Table of Contents">
+<ul class="Documentation-toc"></ul>
+</div><p>Deprecated: use GoodM.
+</p>
+</div><div class="Documentation-typeMethod">
+<h4 tabindex="-1" id="BadT.GoodM" data-kind="method" class="Documentation-typeMethodHeader">
+<span>func (BadT) <a class="Documentation-source" href="src">GoodM</a> <a class="Documentation-idLink" href="#BadT.GoodM">¶</a></span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+<div class="Documentation-declaration">
+<pre>func (<a href="#BadT">BadT</a>) GoodM()</pre>
+</div>
+</div>
</div><div class="Documentation-type">
<h4 tabindex="-1" id="GoodT" data-kind="type" class="Documentation-typeHeader">
<span>type <a class="Documentation-source" href="src">GoodT</a> <a class="Documentation-idLink" href="#GoodT">¶</a></span>
@@ -151,7 +204,8 @@
<div class="Documentation-declaration">
<pre>func (<a href="#GoodT">GoodT</a>) GoodM()</pre>
</div>
-</div></div></section></div>
+</div>
+</div></section></div>
----
<ul role="group" id="doc-outline">
<li role="none">
@@ -203,10 +257,37 @@
</a>
<ul role="group" id="nav-group-types">
<li role="none">
-<a href="#BadT" role="treeitem" aria-level="3" tabindex="-1" title="type BadT"
+<a href="#BadT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
+data-aria-owns="nav.group.BadT" title="type BadT"
data-gtmc="doc outline link">
type BadT
</a>
+<ul role="group" id="nav.group.BadT">
+<li role="none">
+<a href="#NewBadTBad" role="treeitem" aria-level="4" tabindex="-1"
+title="NewBadTBad()" data-gtmc="doc outline link">
+NewBadTBad()
+</a>
+</li>
+<li role="none">
+<a href="#NewBadTGood" role="treeitem" aria-level="4" tabindex="-1"
+title="NewBadTGood()" data-gtmc="doc outline link">
+NewBadTGood()
+</a>
+</li>
+<li role="none">
+<a href="#BadT.BadM" role="treeitem" aria-level="4" tabindex="-1"
+title="BadM()" data-gtmc="doc outline link">
+BadM()
+</a>
+</li>
+<li role="none">
+<a href="#BadT.GoodM" role="treeitem" aria-level="4" tabindex="-1"
+title="GoodM()" data-gtmc="doc outline link">
+GoodM()
+</a>
+</li>
+</ul>
</li>
<li role="none">
<a href="#GoodT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
@@ -257,6 +338,10 @@
</optgroup>
<optgroup label="Types">
<option value="BadT">type BadT</option>
+<option value="NewBadTBad">NewBadTBad()</option>
+<option value="NewBadTGood">NewBadTGood()</option>
+<option value="BadT.BadM">BadM()</option>
+<option value="BadT.GoodM">GoodM()</option>
<option value="GoodT">type GoodT</option>
<option value="NewGoodTBad">NewGoodTBad()</option>
<option value="NewGoodTGood">NewGoodTGood()</option>
diff --git a/internal/godoc/dochtml/testdata/deprecated-on.golden b/internal/godoc/dochtml/testdata/deprecated-on.golden
index f0c5c39..2a58e60 100644
--- a/internal/godoc/dochtml/testdata/deprecated-on.golden
+++ b/internal/godoc/dochtml/testdata/deprecated-on.golden
@@ -14,6 +14,14 @@
<li class="Documentation-indexFunction">
<a href="#GoodF">func GoodF()</a></li>
<li class="Documentation-indexType"><a href="#BadT">type BadT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
+<li><ul class="Documentation-indexTypeFunctions">
+<li><a href="#NewBadTBad">func NewBadTBad() BadT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
+<li><a href="#NewBadTGood">func NewBadTGood() BadT</a></li>
+</ul></li>
+<li><ul class="Documentation-indexTypeMethods">
+<li><a href="#BadT.BadM">func (BadT) BadM()</a><span class="Documentation-indexDeprecated">deprecated</span></li>
+<li><a href="#BadT.GoodM">func (BadT) GoodM()</a></li>
+</ul></li>
<li class="Documentation-indexType"><a href="#GoodT">type GoodT</a></li>
<li><ul class="Documentation-indexTypeFunctions">
<li><a href="#NewGoodTBad">func NewGoodTBad() GoodT</a><span class="Documentation-indexDeprecated">deprecated</span></li>
@@ -109,6 +117,65 @@
Deprecated: use GoodT.
Don't use this.
</p>
+<div class="Documentation-typeFunc">
+<details class="Documentation-deprecatedDetails">
+<summary>
+<h4 tabindex="-1" id="NewBadTBad" data-kind="function" class="Documentation-typeFuncHeader">
+<span>
+func <a class="Documentation-source" href="src">NewBadTBad</a> <a class="Documentation-idLink" href="#NewBadTBad">¶</a>
+<span class="Documentation-deprecatedBody">deprecated</span>
+</span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+</summary>
+<div class="Documentation-declaration">
+<pre>func NewBadTBad() <a href="#BadT">BadT</a></pre>
+</div>
+<div role="navigation" aria-label="Table of Contents">
+<ul class="Documentation-toc"></ul>
+</div><p>Deprecated: use NewBadTGood.
+</p>
+</details>
+</div><div class="Documentation-typeFunc">
+<h4 tabindex="-1" id="NewBadTGood" data-kind="function" class="Documentation-typeFuncHeader">
+<span>func <a class="Documentation-source" href="src">NewBadTGood</a> <a class="Documentation-idLink" href="#NewBadTGood">¶</a></span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+<div class="Documentation-declaration">
+<pre>func NewBadTGood() <a href="#BadT">BadT</a></pre>
+</div>
+</div><div class="Documentation-typeMethod">
+<details class="Documentation-deprecatedDetails">
+<summary>
+<h4 tabindex="-1" id="BadT.BadM" data-kind="method" class="Documentation-typeMethodHeader">
+<span>
+func (BadT) <a class="Documentation-source" href="src">BadM</a> <a class="Documentation-idLink" href="#BadT.BadM">¶</a>
+<span class="Documentation-deprecatedBody">deprecated</span>
+</span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+</summary>
+<div class="Documentation-declaration">
+<pre>func (<a href="#BadT">BadT</a>) BadM()</pre>
+</div>
+<div role="navigation" aria-label="Table of Contents">
+<ul class="Documentation-toc"></ul>
+</div><p>Deprecated: use GoodM.
+</p>
+</details>
+</div><div class="Documentation-typeMethod">
+<h4 tabindex="-1" id="BadT.GoodM" data-kind="method" class="Documentation-typeMethodHeader">
+<span>func (BadT) <a class="Documentation-source" href="src">GoodM</a> <a class="Documentation-idLink" href="#BadT.GoodM">¶</a></span>
+<span class="Documentation-sinceVersion">
+</span>
+</h4>
+<div class="Documentation-declaration">
+<pre>func (<a href="#BadT">BadT</a>) GoodM()</pre>
+</div>
+</div>
</details>
</div><div class="Documentation-type">
<h4 tabindex="-1" id="GoodT" data-kind="type" class="Documentation-typeHeader">
@@ -179,7 +246,8 @@
<div class="Documentation-declaration">
<pre>func (<a href="#GoodT">GoodT</a>) GoodM()</pre>
</div>
-</div></div></section></div>
+</div>
+</div></section></div>
----
<ul role="group" id="doc-outline">
<li role="none">
@@ -231,10 +299,37 @@
</a>
<ul role="group" id="nav-group-types">
<li role="none">
-<a href="#BadT" role="treeitem" aria-level="3" tabindex="-1" title="type BadT"
+<a href="#BadT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
+data-aria-owns="nav.group.BadT" title="type BadT"
data-gtmc="doc outline link">
type BadT
</a>
+<ul role="group" id="nav.group.BadT">
+<li role="none">
+<a href="#NewBadTBad" role="treeitem" aria-level="4" tabindex="-1"
+title="NewBadTBad()" data-gtmc="doc outline link">
+NewBadTBad()
+</a>
+</li>
+<li role="none">
+<a href="#NewBadTGood" role="treeitem" aria-level="4" tabindex="-1"
+title="NewBadTGood()" data-gtmc="doc outline link">
+NewBadTGood()
+</a>
+</li>
+<li role="none">
+<a href="#BadT.BadM" role="treeitem" aria-level="4" tabindex="-1"
+title="BadM()" data-gtmc="doc outline link">
+BadM()
+</a>
+</li>
+<li role="none">
+<a href="#BadT.GoodM" role="treeitem" aria-level="4" tabindex="-1"
+title="GoodM()" data-gtmc="doc outline link">
+GoodM()
+</a>
+</li>
+</ul>
</li>
<li role="none">
<a href="#GoodT" role="treeitem" aria-expanded="false" aria-level="3" tabindex="-1"
@@ -285,6 +380,10 @@
</optgroup>
<optgroup label="Types">
<option value="BadT">type BadT</option>
+<option value="NewBadTBad">NewBadTBad()</option>
+<option value="NewBadTGood">NewBadTGood()</option>
+<option value="BadT.BadM">BadM()</option>
+<option value="BadT.GoodM">GoodM()</option>
<option value="GoodT">type GoodT</option>
<option value="NewGoodTBad">NewGoodTBad()</option>
<option value="NewGoodTGood">NewGoodTGood()</option>
diff --git a/internal/godoc/dochtml/testdata/deprecated.go b/internal/godoc/dochtml/testdata/deprecated.go
index 0382826..23bed0f 100644
--- a/internal/godoc/dochtml/testdata/deprecated.go
+++ b/internal/godoc/dochtml/testdata/deprecated.go
@@ -26,11 +26,6 @@
type GoodT int
-// BadT is bad.
-// Deprecated: use GoodT.
-// Don't use this.
-type BadT int
-
func NewGoodTGood() GoodT {}
// NewGoodTBad is bad.
@@ -42,3 +37,18 @@
// BadM is bad.
// Deprecated: use GoodM.
func (GoodT) BadM() {}
+
+// BadT is bad.
+// Deprecated: use GoodT.
+// Don't use this.
+type BadT int
+
+func NewBadTGood() BadT {}
+
+// Deprecated: use NewBadTGood.
+func NewBadTBad() BadT {}
+
+func (BadT) GoodM() {}
+
+// Deprecated: use GoodM.
+func (BadT) BadM() {}
diff --git a/internal/godoc/dochtml/testdata/everydecl.golden b/internal/godoc/dochtml/testdata/everydecl.golden
index 72426d4..e7e8d95 100644
--- a/internal/godoc/dochtml/testdata/everydecl.golden
+++ b/internal/godoc/dochtml/testdata/everydecl.golden
@@ -185,7 +185,8 @@
</div><p>method
BUG(uid): this verifies that notes are rendered
</p>
-</div></div></section><h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>
+</div>
+</div></section><h3 tabindex="-1" id="pkg-notes" class="Documentation-notesHeader">Notes <a href="#pkg-notes">¶</a></h3>
<section class="Documentation-notes"><div class="Documentation-note">
<h3 tabindex="-1" id="pkg-note-BUG" class="Documentation-noteHeader">Bugs <a href="#pkg-note-BUG">¶</a></h3>
<ul class="Documentation-noteList" style="padding-left: 20px; list-style: initial;">