Skip to content

Commit 7942c13

Browse files
committed
content,internal: add build context dropdown to unit page
Adds build context of the documentation to the unit page. When there is a single buildcontext and it is linux/amd64 nothing will be displayed. A single non-standard build context will show "Rendered for <build context>" and multiple build contexts will show "Rendered for" with a select element to switch the current build context. Fixes golang/go#37232 Change-Id: I06ddbced9a444f3d5af19b189c509abc3241e4dc Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/297552 Trust: Jamal Carvalho <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent eae9ab7 commit 7942c13

File tree

11 files changed

+81
-21
lines changed

11 files changed

+81
-21
lines changed

content/static/css/unit.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
@import './unit_header.css';
88
@import './unit_fixed_header.css';
9+
@import './unit_build_context.css';
910

1011
.Unit-content {
1112
margin: auto;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
* Copyright 2020 The Go Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
.UnitBuildContext-titleContext label,
8+
.UnitBuildContext-singleContext {
9+
color: var(--gray-4);
10+
font-size: 0.875rem;
11+
}
12+
.UnitBuildContext-singleContext {
13+
padding: 0.35rem 0;
14+
}
15+
.UnitBuildContext-titleContext select {
16+
border-color: var(--gray-7);
17+
color: var(--gray-4);
18+
margin-left: 0.25rem;
19+
min-width: 6rem;
20+
padding: 0.25rem 0.125rem;
21+
}
22+
.UnitBuildContext-titleContext option {
23+
color: var(--gray-4);
24+
}
25+
26+
.UnitDoc .UnitBuildContext-titleContext {
27+
position: relative;
28+
}
29+
30+
.UnitDoc .UnitBuildContext-titleContext label,
31+
.UnitDoc .UnitBuildContext-singleContext {
32+
bottom: 0.875rem;
33+
position: absolute;
34+
right: 0;
35+
}

content/static/css/unit_doc.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,3 @@
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/css/unit_fixed_header.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
top: 1.125rem;
151151
width: 1.5rem;
152152
}
153-
@media only screen and (min-width: 80rem) {
153+
@media only screen and (min-width: 90rem) {
154154
.UnitFixedHeader-overflowContainer {
155155
display: none;
156156
}
@@ -216,12 +216,12 @@
216216
padding: 0.5rem;
217217
}
218218
}
219-
@media only screen and (min-width: 64rem) {
219+
@media only screen and (min-width: 70rem) {
220220
.UnitHeaderFixed-detailItem--md {
221221
display: block;
222222
}
223223
}
224-
@media only screen and (min-width: 80rem) {
224+
@media only screen and (min-width: 90rem) {
225225
.UnitHeaderFixed-detailItem--lg {
226226
display: block;
227227
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!--
2+
Copyright 2021 The Go Authors. All rights reserved.
3+
Use of this source code is governed by a BSD-style
4+
license that can be found in the LICENSE file.
5+
-->
6+
7+
{{define "unit_build_context"}}
8+
{{if .BuildContexts}}
9+
{{if gt (len .BuildContexts) 1}}
10+
<div class="UnitBuildContext-titleContext">
11+
<label><a href="https://go.dev/about#build-context">Rendered for</a>
12+
<select class="js-buildContextSelect">
13+
{{range .BuildContexts}}
14+
<option{{if eq .GOOS $.GOOS}} selected{{end}} value="{{.GOOS}}">{{.GOOS}}/{{.GOARCH}}</option>
15+
{{end}}
16+
</select>
17+
</label>
18+
</div>
19+
{{else if not (eq .GOOS "all")}}
20+
<div class="UnitBuildContext-titleContext">
21+
<div class="UnitBuildContext-singleContext"><a href="/about#build-context">Rendered for</a> {{.GOOS}}/{{.GOARCH}}</div>
22+
</div>
23+
{{end}}
24+
{{end}}
25+
{{end}}

content/static/html/helpers/_unit_doc.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
<h2 class="UnitDoc-title" id="section-documentation">
1010
<img height="25px" width="20px" src="/static/img/pkg-icon-doc_20x12.svg" alt="">Documentation
1111
</h2>
12+
{{template "unit_build_context" .}}
1213
<div class="Documentation js-documentation">
1314
{{if .DocBody.String}}
1415
{{.DocBody}}
15-
{{if or (ne .GOOS "all") (ne .GOARCH "all")}}
16-
<div class=UnitDoc-buildContext>
17-
GOOS={{.GOOS}}, GOARCH={{.GOARCH}}
18-
</div>
19-
{{end}}
2016
{{else}}
2117
<div class="UnitDoc-emptySection">
2218
<img src="/static/img/gopher-airplane.svg" alt="The Go Gopher"/>

content/static/html/helpers/_unit_fixed_header.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
{{.Details.ImportedByCount}} <span>Imported by</span>
7979
</a>
8080
</span>
81+
<span class="UnitHeaderFixed-detailItem UnitHeaderFixed-detailItem--lg">
82+
{{template "unit_build_context" .Details}}
83+
</span>
8184
{{end}}
8285
</div>
8386
<div class="UnitFixedHeader-overflowContainer">

content/static/js/unit.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

content/static/js/unit.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

content/static/js/unit.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,8 @@ const directoriesOption = document.querySelector('.js-directoriesOption');
8181
if (!unitDirectories && directoriesOption) {
8282
directoriesOption.setAttribute('disabled', 'true');
8383
}
84+
document.querySelectorAll('.js-buildContextSelect').forEach(el => {
85+
el.addEventListener('change', e => {
86+
window.location.search = `?GOOS=${(e.target as HTMLSelectElement).value}`;
87+
});
88+
});

internal/frontend/server_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ func serverTestCases() []serverTestCase {
780780
wantStatusCode: http.StatusOK,
781781
want: in("",
782782
pagecheck.UnitHeader(pkgV100, unversioned, isPackage),
783-
notIn(".UnitDoc-buildContext")),
783+
notIn(".UnitBuildContext-titleContext")),
784784
},
785785
{
786786
name: "package default redirect",
@@ -1041,31 +1041,31 @@ func serverTestCases() []serverTestCase {
10411041
wantStatusCode: http.StatusOK,
10421042
want: in("",
10431043
in(".Documentation-variables", hasText("var L")),
1044-
in(".UnitDoc-buildContext", hasText("GOOS=linux"))),
1044+
in(".UnitBuildContext-titleContext", hasText("linux/amd64"))),
10451045
},
10461046
{
10471047
name: "two docs linux",
10481048
urlPath: "/a.com/two/pkg?GOOS=linux",
10491049
wantStatusCode: http.StatusOK,
10501050
want: in("",
10511051
in(".Documentation-variables", hasText("var L")),
1052-
in(".UnitDoc-buildContext", hasText("GOOS=linux"))),
1052+
in(".UnitBuildContext-titleContext", hasText("linux/amd64"))),
10531053
},
10541054
{
10551055
name: "two docs windows",
10561056
urlPath: "/a.com/two/pkg?GOOS=windows",
10571057
wantStatusCode: http.StatusOK,
10581058
want: in("",
10591059
in(".Documentation-variables", hasText("var W")),
1060-
in(".UnitDoc-buildContext", hasText("GOOS=windows"))),
1060+
in(".UnitBuildContext-titleContext", hasText("windows/amd64"))),
10611061
},
10621062
{
10631063
name: "two docs no match",
10641064
urlPath: "/a.com/two/pkg?GOOS=dragonfly",
10651065
wantStatusCode: http.StatusOK,
10661066
want: in("",
10671067
notIn(".Documentation-variables"),
1068-
notIn(".UnitDoc-buildContext")),
1068+
notIn(".UnitBuildContext-titleContext")),
10691069
},
10701070
}
10711071
}

0 commit comments

Comments
 (0)