content/static: add source link to source files
Adds a link to the header of the source files section
to view the source of a package at the origin.
Change-Id: Ieef083c08602e0ab0d498e422952738bac80d011
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/263957
Trust: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
diff --git a/content/static/css/unit_files.css b/content/static/css/unit_files.css
index 189c521..6afff8f 100644
--- a/content/static/css/unit_files.css
+++ b/content/static/css/unit_files.css
@@ -18,6 +18,27 @@
margin: auto 1rem auto 0;
width: auto;
}
+.UnitFiles-titleLink {
+ position: relative;
+}
+.UnitFiles-titleLink a {
+ bottom: 1rem;
+ font-size: 0.875rem;
+ position: absolute;
+ right: 0;
+}
+.UnitFiles-titleLink a:after {
+ background-image: url(/static/img/icon-launch.svg);
+ background-repeat: no-repeat;
+ background-size: 0.875rem 1.25rem;
+ content: '';
+ display: inline-block;
+ height: 1rem;
+ left: 0.3125rem;
+ position: relative;
+ top: 0.125rem;
+ width: 1rem;
+}
.UnitFiles-fileList {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(10.5rem, auto));
diff --git a/content/static/html/helpers/_unit_files.tmpl b/content/static/html/helpers/_unit_files.tmpl
index 2f7626e..d81b7a6 100644
--- a/content/static/html/helpers/_unit_files.tmpl
+++ b/content/static/html/helpers/_unit_files.tmpl
@@ -9,10 +9,15 @@
<h2 class="UnitFiles-title">
<img height="16px" width="12px" src="/static/img/pkg-icon-file_16x12.svg" alt="">Source Files
</h2>
+ <div class="UnitFiles-titleLink">
+ <a href="{{.SourceURL}}" target="_blank" rel="noopener">View all</a>
+ </div>
<div>
<ul class="UnitFiles-fileList">
{{- range .SourceFiles -}}
- <li class="UnitFiles-file"><a href="{{.URL}}" target="_blank" title="{{.Name}}">{{.Name}}</a></li>
+ <li class="UnitFiles-file">
+ <a href="{{.URL}}" target="_blank" rel="noopener" title="{{.Name}}">{{.Name}}</a>
+ </li>
{{- end -}}
</ul>
</div>
diff --git a/internal/frontend/unit_main.go b/internal/frontend/unit_main.go
index 772d507..67d3817 100644
--- a/internal/frontend/unit_main.go
+++ b/internal/frontend/unit_main.go
@@ -57,6 +57,9 @@
// RepositoryURL is the URL to the repository containing the package.
RepositoryURL string
+ // SourceURL is the URL to the source of the package.
+ SourceURL string
+
// ExpandReadme is holds the expandable readme state.
ExpandReadme bool
}
@@ -170,6 +173,7 @@
DocBody: docBody,
SourceFiles: files,
RepositoryURL: um.SourceInfo.RepoURL(),
+ SourceURL: um.SourceInfo.DirectoryURL(internal.Suffix(um.Path, um.ModulePath)),
MobileOutline: mobileOutline,
NumImports: len(unit.Imports),
ImportedByCount: importedByCount,