content/static: move mobile outline container to frontend template
The container for the mobile outline was part of
a template used in the dochtml package making it
difficult to extend from the frontend. Limiting
the dochtml sidenav-mobile template to the minimum
necessary html will allow us to add the readme
headings to the mobile outline. This change moves
the non-dochtml html to a new file to do just that.
For golang/go#43325
Change-Id: Ieef429034e7082215bd2cdb75bbf88f30683cf96
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/310371
Trust: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/content/static/html/doc/sidenav-mobile.tmpl b/content/static/html/doc/sidenav-mobile.tmpl
index ac92e9d..63f6d91 100644
--- a/content/static/html/doc/sidenav-mobile.tmpl
+++ b/content/static/html/doc/sidenav-mobile.tmpl
@@ -3,62 +3,49 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
-<nav class="DocNavMobile js-mobileNav">
- <label for="DocNavMobile-select" class="DocNavMobile-label">
- <svg class="DocNavMobile-selectIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="18px" height="18px">
- <path d="M0 0h24v24H0z" fill="none"/><path d="M3 9h14V7H3v2zm0 4h14v-2H3v2zm0 4h14v-2H3v2zm16 0h2v-2h-2v2zm0-10v2h2V7h-2zm0 6h2v-2h-2v2z"/>
- </svg>
- <span class="DocNavMobile-selectText js-mobileNavSelectText">Outline</span>
- </label>
- <select id="DocNavMobile-select" class="DocNavMobile-select">
- <option value="">Outline</option>
- <option class="js-readmeOption" value="section-readme">README</option>
- <optgroup label="Documentation">
- {{if or .Doc (index .Examples.Map "")}}
- <option value="pkg-overview">Overview</option>
- {{end}}
- {{if or .Consts .Vars .Funcs .Types}}
- <option value="pkg-index">Index</option>
- {{end}}
- {{if .Examples.List}}
- <option value="pkg-examples">Examples</option>
- {{end}}
- {{if .Consts}}
- <option value="pkg-constants">Constants</option>
- {{end}}
- {{if .Vars}}
- <option value="pkg-variables">Variables</option>
- {{end}}
- </optgroup>
- {{if .Funcs}}
- <optgroup label="Functions">
- {{range .Funcs}}
- <option value="{{.Name}}">{{render_short_synopsis .Decl}}</option>
- {{end}}
- </optgroup>
+
+<optgroup label="Documentation">
+ {{if or .Doc (index .Examples.Map "")}}
+ <option value="pkg-overview">Overview</option>
+ {{end}}
+ {{if or .Consts .Vars .Funcs .Types}}
+ <option value="pkg-index">Index</option>
+ {{end}}
+ {{if .Examples.List}}
+ <option value="pkg-examples">Examples</option>
+ {{end}}
+ {{if .Consts}}
+ <option value="pkg-constants">Constants</option>
+ {{end}}
+ {{if .Vars}}
+ <option value="pkg-variables">Variables</option>
+ {{end}}
+</optgroup>
+{{if .Funcs}}
+ <optgroup label="Functions">
+ {{range .Funcs}}
+ <option value="{{.Name}}">{{render_short_synopsis .Decl}}</option>
{{end}}
- {{if .Types}}
- <optgroup label="Types">
- {{range .Types}}
- {{$tname := .Name}}
- <option value="{{$tname}}">type {{$tname}}</option>
- {{range .Funcs}}
- <option value="{{.Name}}">{{render_short_synopsis .Decl}}</option>
- {{end}}
- {{range .Methods}}
- <option value="{{$tname}}.{{.Name}}">{{render_short_synopsis .Decl}}</option>
- {{end}}
- {{end}} {{/* range .Types */}}
- </optgroup>
+ </optgroup>
+{{end}}
+{{if .Types}}
+ <optgroup label="Types">
+ {{range .Types}}
+ {{$tname := .Name}}
+ <option value="{{$tname}}">type {{$tname}}</option>
+ {{range .Funcs}}
+ <option value="{{.Name}}">{{render_short_synopsis .Decl}}</option>
+ {{end}}
+ {{range .Methods}}
+ <option value="{{$tname}}.{{.Name}}">{{render_short_synopsis .Decl}}</option>
+ {{end}}
+ {{end}} {{/* range .Types */}}
+ </optgroup>
+{{end}}
+{{if .Notes}}
+ <optgroup label="Notes">
+ {{range $marker, $item := .Notes}}
+ <option value="pkg-note-{{$marker}}">{{(index $.NoteHeaders $marker).Label}}s</option>
{{end}}
- {{if .Notes}}
- <optgroup label="Notes">
- {{range $marker, $item := .Notes}}
- <option value="pkg-note-{{$marker}}">{{(index $.NoteHeaders $marker).Label}}s</option>
- {{end}}
- </optgroup>
- {{end}}
- <option class="js-sourcefilesOption" value="section-sourcefiles">Source Files</option>
- <option class="js-directoriesOption" value="section-directories">Directories</option>
- </select>
-</nav>
+ </optgroup>
+{{end}}
diff --git a/content/static/html/helpers/_unit_outline_mobile.tmpl b/content/static/html/helpers/_unit_outline_mobile.tmpl
new file mode 100644
index 0000000..1a414c9
--- /dev/null
+++ b/content/static/html/helpers/_unit_outline_mobile.tmpl
@@ -0,0 +1,23 @@
+<!--
+ Copyright 2021 The Go Authors. All rights reserved.
+ Use of this source code is governed by a BSD-style
+ license that can be found in the LICENSE file.
+-->
+
+{{define "unit_outline_mobile"}}
+ <nav class="DocNavMobile js-mobileNav">
+ <label for="DocNavMobile-select" class="DocNavMobile-label">
+ <svg class="DocNavMobile-selectIcon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="black" width="18px" height="18px">
+ <path d="M0 0h24v24H0z" fill="none"/><path d="M3 9h14V7H3v2zm0 4h14v-2H3v2zm0 4h14v-2H3v2zm16 0h2v-2h-2v2zm0-10v2h2V7h-2zm0 6h2v-2h-2v2z"/>
+ </svg>
+ <span class="DocNavMobile-selectText js-mobileNavSelectText">Outline</span>
+ </label>
+ <select id="DocNavMobile-select" class="DocNavMobile-select">
+ <option value="">Outline</option>
+ <option class="js-readmeOption" value="section-readme">README</option>
+ {{.MobileOutline}}
+ <option class="js-sourcefilesOption" value="section-sourcefiles">Source Files</option>
+ <option class="js-directoriesOption" value="section-directories">Directories</option>
+ </select>
+ </nav>
+{{end}}
diff --git a/content/static/html/pages/unit_details.tmpl b/content/static/html/pages/unit_details.tmpl
index f11d56d..55dfea0 100644
--- a/content/static/html/pages/unit_details.tmpl
+++ b/content/static/html/pages/unit_details.tmpl
@@ -10,7 +10,7 @@
{{define "unit_content"}}
<div class="UnitDetails" data-test-id="UnitDetails">
- {{.Details.MobileOutline}}
+ {{block "unit_outline_mobile" .Details}}{{end}}
<div class="UnitDetails-outline" role="navigation"
aria-label="{{if eq .PageType "std"}}module
{{else}}{{.PageType}}{{end}}details navigation">
diff --git a/internal/godoc/dochtml/dochtml_test.go b/internal/godoc/dochtml/dochtml_test.go
index 9006326..e2a74d1 100644
--- a/internal/godoc/dochtml/dochtml_test.go
+++ b/internal/godoc/dochtml/dochtml_test.go
@@ -79,7 +79,7 @@
t.Errorf("note check: %v", err)
}
- checker = in("#DocNavMobile-select",
+ checker = in("",
in("optgroup[label=Notes]", in("option", hasAttr("value", "pkg-note-BUG"), hasExactText("Bugs"))))
if err := checker(htmlDoc); err != nil {
t.Errorf("note check: %v", err)
@@ -140,7 +140,7 @@
t.Errorf("note check: %v", err)
}
- checker = in("#DocNavMobile-select",
+ checker = in("",
in("optgroup[label=Notes]", in("option", hasAttr("value", "pkg-note-BUG"), hasExactText("Bugs"))))
if err := checker(mobileDoc); err != nil {
t.Errorf("note check: %v", err)