Skip to content

Commit 4c18cf8

Browse files
committed
internal/frontend: show build context on doc page
If it is not all/all, show the build context at the bottom of the documentation. This is just a preliminary implementation, so users can experience the feature before we provide a proper UI. For golang/go#37232 Change-Id: Ic48a246a8793e61917a31f66580249997255ba77 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/290095 Trust: Jonathan Amsterdam <jba@google.com> Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Jamal Carvalho <jamal@golang.org>
1 parent 72b4ab8 commit 4c18cf8

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

content/static/css/unit_doc.css

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@
3535
.UnitDoc .Documentation h4 {
3636
font-size: 1.375rem;
3737
}
38+
.UnitDoc-buildContext {
39+
font-style: italic;
40+
padding-top: 1rem;
41+
text-align: right;
42+
}

content/static/html/helpers/_unit_doc.tmpl

+5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
<div class="Documentation js-documentation">
1313
{{if .DocBody.String}}
1414
{{.DocBody}}
15+
{{if or (ne .GOOS "all") (ne .GOARCH "all")}}
16+
<div class=UnitDoc-buildContext>
17+
GOOS={{.GOOS}}, GOARCH={{.GOARCH}}
18+
</div>
19+
{{end}}
1520
{{else}}
1621
<div class="UnitDoc-emptySection">
1722
<img src="/static/img/gopher-airplane.svg" alt="The Go Gopher"/>

internal/frontend/server_test.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ func insertTestModules(ctx context.Context, t *testing.T, mods []testModule) {
351351

352352
var (
353353
in = htmlcheck.In
354+
notIn = htmlcheck.NotIn
354355
hasText = htmlcheck.HasText
355356
attr = htmlcheck.HasAttr
356357

@@ -778,7 +779,9 @@ func serverTestCases() []serverTestCase {
778779
name: "package default",
779780
urlPath: fmt.Sprintf("/%s", sample.PackagePath),
780781
wantStatusCode: http.StatusOK,
781-
want: pagecheck.UnitHeader(pkgV100, unversioned, isPackage),
782+
want: in("",
783+
pagecheck.UnitHeader(pkgV100, unversioned, isPackage),
784+
notIn(".UnitDoc-buildContext")),
782785
},
783786
{
784787
name: "package default redirect",
@@ -1037,25 +1040,33 @@ func serverTestCases() []serverTestCase {
10371040
name: "two docs default",
10381041
urlPath: "/a.com/two/pkg",
10391042
wantStatusCode: http.StatusOK,
1040-
want: in(".Documentation-variables", hasText("var L")),
1043+
want: in("",
1044+
in(".Documentation-variables", hasText("var L")),
1045+
in(".UnitDoc-buildContext", hasText("GOOS=linux"))),
10411046
},
10421047
{
10431048
name: "two docs linux",
10441049
urlPath: "/a.com/two/pkg?GOOS=linux",
10451050
wantStatusCode: http.StatusOK,
1046-
want: in(".Documentation-variables", hasText("var L")),
1051+
want: in("",
1052+
in(".Documentation-variables", hasText("var L")),
1053+
in(".UnitDoc-buildContext", hasText("GOOS=linux"))),
10471054
},
10481055
{
10491056
name: "two docs windows",
10501057
urlPath: "/a.com/two/pkg?GOOS=windows",
10511058
wantStatusCode: http.StatusOK,
1052-
want: in(".Documentation-variables", hasText("var W")),
1059+
want: in("",
1060+
in(".Documentation-variables", hasText("var W")),
1061+
in(".UnitDoc-buildContext", hasText("GOOS=windows"))),
10531062
},
10541063
{
10551064
name: "two docs no match",
10561065
urlPath: "/a.com/two/pkg?GOOS=dragonfly",
10571066
wantStatusCode: http.StatusOK,
1058-
want: htmlcheck.NotIn(".Documentation-variables"),
1067+
want: in("",
1068+
notIn(".Documentation-variables"),
1069+
notIn(".UnitDoc-buildContext")),
10591070
},
10601071
}
10611072
}

internal/frontend/unit_main.go

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ type MainDetails struct {
7979
// tag on the main unit page.
8080
DocSynopsis string
8181

82+
// GOOS and GOARCH are the build context for the doc.
83+
GOOS, GOARCH string
84+
8285
// SourceFiles contains .go files for the package.
8386
SourceFiles []*File
8487

@@ -161,11 +164,14 @@ func fetchMainDetails(ctx context.Context, ds internal.DataSource, um *internal.
161164
docLinks, modLinks []link
162165
files []*File
163166
synopsis string
167+
goos, goarch string
164168
)
165169

166170
doc := internal.DocumentationForBuildContext(unit.Documentation, bc)
167171
if doc != nil {
168172
synopsis = doc.Synopsis
173+
goos = doc.GOOS
174+
goarch = doc.GOARCH
169175
end := middleware.ElapsedStat(ctx, "DecodePackage")
170176
docPkg, err := godoc.DecodePackage(doc.Source)
171177
end()
@@ -229,6 +235,8 @@ func fetchMainDetails(ctx context.Context, ds internal.DataSource, um *internal.
229235
DocOutline: docParts.Outline,
230236
DocBody: docParts.Body,
231237
DocSynopsis: synopsis,
238+
GOOS: goos,
239+
GOARCH: goarch,
232240
SourceFiles: files,
233241
RepositoryURL: um.SourceInfo.RepoURL(),
234242
SourceURL: um.SourceInfo.DirectoryURL(internal.Suffix(um.Path, um.ModulePath)),

0 commit comments

Comments
 (0)