content,internal: add metadata tab content to unit page
Adds package details data to unit struct and
render pages for versions, licenses, imports
and imported by tabs.
Change-Id: I38ce022bd7ea4a2df53310f3d2dd631fcca020ce
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/256879
Trust: Jamal Carvalho <jamal@golang.org>
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/content/static/html/helpers/_importedby.tmpl b/content/static/html/helpers/_importedby.tmpl
new file mode 100644
index 0000000..8cff4f2
--- /dev/null
+++ b/content/static/html/helpers/_importedby.tmpl
@@ -0,0 +1,39 @@
+<!--
+ Copyright 2019 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 "importedby"}}
+ <div class="ImportedBy">
+ {{if .ImportedBy}}
+ <p>
+ <b>Known {{pluralize .Total "importer"}}:</b> {{.Total}}{{if not .TotalIsExact}}+{{end}}
+ </p>
+ {{template "sections" .ImportedBy}}
+ {{else}}
+ {{template "empty_content" "No known importers for this package!"}}
+ {{end}}
+ </div>
+{{end}}
+
+{{define "sections"}}
+ <ul class="ImportedBy-list">
+ {{range .}}
+ {{template "section" .}}
+ {{end}}
+ </ul>
+{{end}}
+
+{{define "section"}}
+ {{if .Subs}}
+ <details>
+ <summary>{{.Prefix}} ({{.NumLines}})</summary>
+ <div class="Details-content">
+ {{template "sections" .Subs}}
+ </div>
+ </details>
+ {{else}}
+ <li class="Details-indent"><a class="u-breakWord" href="/{{.Prefix}}">{{.Prefix}}</a></li>
+ {{end}}
+{{end}}
diff --git a/content/static/html/helpers/_imports.tmpl b/content/static/html/helpers/_imports.tmpl
new file mode 100644
index 0000000..7fa1da4
--- /dev/null
+++ b/content/static/html/helpers/_imports.tmpl
@@ -0,0 +1,38 @@
+<!--
+ Copyright 2020 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 "imports"}}
+ <div>
+ {{if or .ExternalImports .InternalImports .StdLib}}
+ {{if .ExternalImports}}
+ <h2 class="Imports-heading">Imports</h2>
+ <ul class="Imports-list">
+ {{range .ExternalImports}}
+ <li><a href="/{{.}}">{{.}}</a></li>
+ {{end}}
+ </ul>
+ {{end}}
+ {{if .InternalImports}}
+ <h2 class="Imports-heading">Imports in module “{{.ModulePath}}”</h2>
+ <ul class="Imports-list">
+ {{range .InternalImports}}
+ <li><a href="/{{.}}">{{.}}</a></li>
+ {{end}}
+ </ul>
+ {{end}}
+ {{if .StdLib}}
+ <h2 class="Imports-heading">Standard Library Imports</h2>
+ <ul class="Imports-list">
+ {{range .StdLib}}
+ <li><a href="/{{.}}">{{.}}</a></li>
+ {{end}}
+ </ul>
+ {{end}}
+ {{else}}
+ {{template "empty_content" "This package does not have any imports!"}}
+ {{end}}
+ </div>
+{{end}}
diff --git a/content/static/html/helpers/_licenses.tmpl b/content/static/html/helpers/_licenses.tmpl
new file mode 100644
index 0000000..f26b4af
--- /dev/null
+++ b/content/static/html/helpers/_licenses.tmpl
@@ -0,0 +1,16 @@
+<!--
+ Copyright 2020 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 "licenses"}}
+ {{range .Licenses}}
+ <section class="License" id="{{.Anchor}}">
+ <h2><div id="#{{.Anchor}}">{{range $i, $e := .Types}}{{if $i}}, {{end}}{{$e}}{{end}}</div></h2>
+ <p>This is not legal advice. <a href="/license-policy">Read disclaimer.</a></p>
+ <pre class="License-contents">{{printf "%s" .Contents}}</pre>
+ </section>
+ <div class="License-source">Source: {{.Source}}</div>
+ {{end}}
+{{end}}
diff --git a/content/static/html/helpers/_unit_fixed_header.tmpl b/content/static/html/helpers/_unit_fixed_header.tmpl
index d1b2bc2..40adb14 100644
--- a/content/static/html/helpers/_unit_fixed_header.tmpl
+++ b/content/static/html/helpers/_unit_fixed_header.tmpl
@@ -78,7 +78,7 @@
<path d="M0 0h24v24H0z" fill="none"/>
<path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"/>
</svg>
- <select class="UnitFixedHeader-overflowSelect" onchange="location=this.value" tabindex="-1">
+ <select class="UnitFixedHeader-overflowSelect js-overflowSelect" tabindex="-1">
{{range .Tabs}}
<option
value="{{$.CanonicalURLPath}}?tab={{.Name}}"
diff --git a/content/static/html/helpers/_versions.tmpl b/content/static/html/helpers/_versions.tmpl
new file mode 100644
index 0000000..06b083a
--- /dev/null
+++ b/content/static/html/helpers/_versions.tmpl
@@ -0,0 +1,41 @@
+<!--
+ Copyright 2020 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 "module_list"}}
+ {{range $major := .}}
+ <h2>
+ {{.Major}}
+ {{if not (eq $major.ModulePath "std")}}
+ <span class="Versions-modulePath"> – {{$major.ModulePath}}</span>
+ {{end}}
+ </h2>
+ <ul class="Versions-list">
+ {{range $v := $major.Versions}}
+ <li class="Versions-item">
+ <a href="{{$v.Link}}">{{$v.Version}}</a>
+ <span class="Versions-commitTime"> – {{$v.CommitTime}}</span>
+ </li>
+ {{end}}
+ </ul>
+ {{end}}
+{{end}}
+
+{{define "versions"}}
+ <div class="Versions">
+ {{if or .OtherModules .ThisModule}}
+ {{if .OtherModules}}
+ <h2>Versions in this module</h2>
+ {{end}}
+ {{template "module_list" .ThisModule}}
+ {{if .OtherModules}}
+ <h2>Other modules containing this package</h2>
+ {{template "module_list" .OtherModules}}
+ {{end}}
+ {{else}}
+ {{template "empty_content" "No other known versions of this package!"}}
+ {{end}}
+ </div>
+{{end}}
diff --git a/content/static/html/pages/licenses.tmpl b/content/static/html/pages/licenses.tmpl
index 4a2977e..6d1d3ce 100644
--- a/content/static/html/pages/licenses.tmpl
+++ b/content/static/html/pages/licenses.tmpl
@@ -5,12 +5,5 @@
-->
{{define "details_content"}}
- {{range .Licenses}}
- <section class="License" id="{{.Anchor}}">
- <h2><div id="#{{.Anchor}}">{{range $i, $e := .Types}}{{if $i}}, {{end}}{{$e}}{{end}}</div></h2>
- <p>This is not legal advice. <a href="/license-policy">Read disclaimer.</a></p>
- <pre class="License-contents">{{printf "%s" .Contents}}</pre>
- </section>
- <div class="License-source">Source: {{.Source}}</div>
- {{end}}
+ {{block "licenses" .}}{{end}}
{{end}}
diff --git a/content/static/html/pages/pkg_importedby.tmpl b/content/static/html/pages/pkg_importedby.tmpl
index 88aee10..f52c86c 100644
--- a/content/static/html/pages/pkg_importedby.tmpl
+++ b/content/static/html/pages/pkg_importedby.tmpl
@@ -5,35 +5,5 @@
-->
{{define "details_content"}}
- <div class="ImportedBy">
- {{if .ImportedBy}}
- <p>
- <b>Known {{pluralize .Total "importer"}}:</b> {{.Total}}{{if not .TotalIsExact}}+{{end}}
- </p>
- {{template "sections" .ImportedBy}}
- {{else}}
- {{template "empty_content" "No known importers for this package!"}}
- {{end}}
- </div>
-{{end}}
-
-{{define "sections"}}
- <ul class="ImportedBy-list">
- {{range .}}
- {{template "section" .}}
- {{end}}
- </ul>
-{{end}}
-
-{{define "section"}}
- {{if .Subs}}
- <details>
- <summary>{{.Prefix}} ({{.NumLines}})</summary>
- <div class="Details-content">
- {{template "sections" .Subs}}
- </div>
- </details>
- {{else}}
- <li class="Details-indent"><a class="u-breakWord" href="/{{.Prefix}}">{{.Prefix}}</a></li>
- {{end}}
-{{end}}
+ {{block "importedby" .}}{{end}}
+{{end}}
\ No newline at end of file
diff --git a/content/static/html/pages/pkg_imports.tmpl b/content/static/html/pages/pkg_imports.tmpl
index 54cb21c..e5a12b8 100644
--- a/content/static/html/pages/pkg_imports.tmpl
+++ b/content/static/html/pages/pkg_imports.tmpl
@@ -5,34 +5,5 @@
-->
{{define "details_content"}}
- <div>
- {{if or .ExternalImports .InternalImports .StdLib}}
- {{if .ExternalImports}}
- <h2 class="Imports-heading">Imports</h2>
- <ul class="Imports-list">
- {{range .ExternalImports}}
- <li><a href="/{{.}}">{{.}}</a></li>
- {{end}}
- </ul>
- {{end}}
- {{if .InternalImports}}
- <h2 class="Imports-heading">Imports in module “{{.ModulePath}}”</h2>
- <ul class="Imports-list">
- {{range .InternalImports}}
- <li><a href="/{{.}}">{{.}}</a></li>
- {{end}}
- </ul>
- {{end}}
- {{if .StdLib}}
- <h2 class="Imports-heading">Standard Library Imports</h2>
- <ul class="Imports-list">
- {{range .StdLib}}
- <li><a href="/{{.}}">{{.}}</a></li>
- {{end}}
- </ul>
- {{end}}
- {{else}}
- {{template "empty_content" "This package does not have any imports!"}}
- {{end}}
- </div>
+ {{block "imports" .}}{{end}}
{{end}}
diff --git a/content/static/html/pages/unit_importedby.tmpl b/content/static/html/pages/unit_importedby.tmpl
index 00f03c7..f98359f 100644
--- a/content/static/html/pages/unit_importedby.tmpl
+++ b/content/static/html/pages/unit_importedby.tmpl
@@ -10,5 +10,5 @@
{{end}}
{{define "unit_content"}}
-
+ {{block "importedby" .PackageDetails}}{{end}}
{{end}}
diff --git a/content/static/html/pages/unit_imports.tmpl b/content/static/html/pages/unit_imports.tmpl
index 00f03c7..b472735 100644
--- a/content/static/html/pages/unit_imports.tmpl
+++ b/content/static/html/pages/unit_imports.tmpl
@@ -10,5 +10,5 @@
{{end}}
{{define "unit_content"}}
-
+ {{block "imports" .PackageDetails}}{{end}}
{{end}}
diff --git a/content/static/html/pages/unit_licenses.tmpl b/content/static/html/pages/unit_licenses.tmpl
index 00f03c7..269cb63 100644
--- a/content/static/html/pages/unit_licenses.tmpl
+++ b/content/static/html/pages/unit_licenses.tmpl
@@ -10,5 +10,5 @@
{{end}}
{{define "unit_content"}}
-
+ {{block "licenses" .PackageDetails}}{{end}}
{{end}}
diff --git a/content/static/html/pages/unit_versions.tmpl b/content/static/html/pages/unit_versions.tmpl
index 00f03c7..f8741dd 100644
--- a/content/static/html/pages/unit_versions.tmpl
+++ b/content/static/html/pages/unit_versions.tmpl
@@ -10,5 +10,5 @@
{{end}}
{{define "unit_content"}}
-
+ {{block "versions" .PackageDetails}}{{end}}
{{end}}
diff --git a/content/static/html/pages/versions.tmpl b/content/static/html/pages/versions.tmpl
index a6e716d..1d9fa23 100644
--- a/content/static/html/pages/versions.tmpl
+++ b/content/static/html/pages/versions.tmpl
@@ -3,37 +3,6 @@
Use of this source code is governed by a BSD-style
license that can be found in the LICENSE file.
-->
-{{define "module_list"}}
- {{range $major := .}}
- <h2>
- {{.Major}}
- {{if not (eq $major.ModulePath "std")}}
- <span class="Versions-modulePath"> – {{$major.ModulePath}}</span>
- {{end}}
- </h2>
- <ul class="Versions-list">
- {{range $v := $major.Versions}}
- <li class="Versions-item">
- <a href="{{$v.Link}}">{{$v.Version}}</a>
- <span class="Versions-commitTime"> – {{$v.CommitTime}}</span>
- </li>
- {{end}}
- </ul>
- {{end}}
-{{end}}
-
{{define "details_content"}}
- <div class="Versions">
- {{if or .OtherModules .ThisModule}}
- {{if .OtherModules}}
- <h2>Versions in this module</h2>
- {{end}}
- {{template "module_list" .ThisModule}}
- {{if .OtherModules}}
- <h2>Other modules containing this package</h2>
- {{template "module_list" .OtherModules}}
- {{end}}
- {{else}}
- {{template "empty_content" "No other known versions of this package!"}}
- {{end}}
+ {{block "versions" .}}{{end}}
{{end}}
diff --git a/content/static/js/unit_fixed_header.js b/content/static/js/unit_fixed_header.js
index 39c473c..a0b2ee1 100644
--- a/content/static/js/unit_fixed_header.js
+++ b/content/static/js/unit_fixed_header.js
@@ -75,3 +75,10 @@
document.querySelector('.js-fixedHeaderSentinel'),
document.querySelector('.js-fixedHeader')
);
+
+const overflowSelect = document.querySelector('.js-overflowSelect');
+if (overflowSelect) {
+ overflowSelect.addEventListener('change', e => {
+ window.location.href = e.target.value;
+ });
+}
diff --git a/internal/frontend/unit.go b/internal/frontend/unit.go
index b34a5bc..ca80ca8 100644
--- a/internal/frontend/unit.go
+++ b/internal/frontend/unit.go
@@ -73,6 +73,10 @@
// Settings contains settings for the selected tab.
SelectedTab TabSettings
+ // PackageDetails contains data used to render the
+ // versions, licenses, imports, and importedby tabs.
+ PackageDetails interface{}
+
DocBody *safehtml.HTML
DocOutline *safehtml.HTML
MobileOutline *safehtml.HTML
@@ -208,6 +212,14 @@
MobileOutline: mobileOutline,
}
+ if tab != tabDetails {
+ packageDetails, err := fetchDetailsForPackage(r, tab, ds, &unit.UnitMeta)
+ if err != nil {
+ return err
+ }
+ page.PackageDetails = packageDetails
+ }
+
s.servePage(ctx, w, tabSettings.TemplateName, page)
return nil
}