diff --git a/content/static/css/stylesheet.css b/content/static/css/stylesheet.css
index 8c9fb8062..5aa894df8 100644
--- a/content/static/css/stylesheet.css
+++ b/content/static/css/stylesheet.css
@@ -1470,6 +1470,28 @@ pre,
word-wrap: break-word;
}
+.Documentation-indexDeprecated {
+ font-size: 0.875rem;
+ font-style: italic;
+ color: var(--gray-3);
+ margin-left: 0.5rem;
+}
+
+.Documentation-bodyDeprecated {
+ font-size: 1rem;
+ font-style: italic;
+ font-weight: 400;
+ color: var(--gray-3);
+ margin-left: 0.5rem;
+ margin-right: 0.5rem;
+}
+
+.Documentation-deprecatedShowLink {
+ font-size: 1rem;
+ font-weight: 400;
+}
+
+
.Unit-content .Versions {
margin-top: 1rem;
}
diff --git a/content/static/html/doc/body.tmpl b/content/static/html/doc/body.tmpl
index 6574664eb..ff3a0dec4 100644
--- a/content/static/html/doc/body.tmpl
+++ b/content/static/html/doc/body.tmpl
@@ -22,20 +22,39 @@
{{- range .Funcs -}}
{{render_synopsis .Decl}}
+ {{- if .IsDeprecated -}}
+ deprecated
+ {{- end -}}
{{"\n"}}
{{- end -}}
{{- range .Types -}}
{{- $tname := .Name -}}
- type {{$tname}}{{"\n"}}
+ type {{$tname}}
+ {{- if .IsDeprecated -}}
+ deprecated
+ {{- end -}}
+ {{"\n"}}
{{- with .Funcs -}}
{{"\n" -}}
{{- end -}}
{{- with .Methods -}}
{{"\n" -}}
{{- end -}}
{{- end -}}
@@ -86,11 +105,19 @@
{{- $id := safe_id .Name -}}
{{"\n"}}
- {{- template "declaration" . -}}
- {{- template "example" (index $.Examples.Map .Name) -}}
+ {{if not .IsDeprecated}}
+ {{- template "declaration" . -}}
+ {{- template "example" (index $.Examples.Map .Name) -}}
+ {{end}}
{{- end -}}
{{- else -}}
@@ -109,8 +136,10 @@
type {{source_link .Name .Decl}} ¶
{{- template "since_version" .Name -}}
{{"\n"}}
- {{- template "declaration" . -}}
- {{- template "example" (index $.Examples.Map .Name) -}}
+ {{if not .IsDeprecated}}
+ {{- template "declaration" . -}}
+ {{- template "example" (index $.Examples.Map .Name) -}}
+ {{end}}
{{- range .Consts -}}
@@ -128,11 +157,19 @@
{{- $id := safe_id .Name -}}
{{"\n"}}
- {{- template "declaration" . -}}
- {{- template "example" (index $.Examples.Map .Name) -}}
+ {{if not .IsDeprecated}}
+ {{- template "declaration" . -}}
+ {{- template "example" (index $.Examples.Map .Name) -}}
+ {{end}}
{{- end -}}
@@ -141,11 +178,19 @@
{{- $name := (printf "%s.%s" $tname .Name) -}}
{{- $id := (safe_id $name) -}}
{{"\n"}}
- {{- template "declaration" . -}}
- {{- template "example" (index $.Examples.Map $name) -}}
+ {{if not .IsDeprecated}}
+ {{- template "declaration" . -}}
+ {{- template "example" (index $.Examples.Map $name) -}}
+ {{end}}
{{- end -}}
diff --git a/internal/godoc/dochtml/dochtml.go b/internal/godoc/dochtml/dochtml.go
index 6da7bbe64..ba2538d4d 100644
--- a/internal/godoc/dochtml/dochtml.go
+++ b/internal/godoc/dochtml/dochtml.go
@@ -25,7 +25,9 @@ import (
"github.com/google/safehtml/legacyconversions"
"github.com/google/safehtml/template"
"github.com/google/safehtml/uncheckedconversions"
+ "golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/derrors"
+ "golang.org/x/pkgsite/internal/experiment"
"golang.org/x/pkgsite/internal/godoc/dochtml/internal/render"
"golang.org/x/pkgsite/internal/godoc/internal/doc"
)
@@ -91,6 +93,28 @@ func Render(ctx context.Context, fset *token.FileSet, p *doc.Package, opt Render
opt.Limit = 10 * megabyte
}
+ if !experiment.IsActive(ctx, internal.ExperimentDeprecatedDoc) {
+ //Simpler to clear the fields here than to add experiment checks in the templates.
+ for _, c := range p.Consts {
+ c.IsDeprecated = false
+ }
+ for _, v := range p.Vars {
+ v.IsDeprecated = false
+ }
+ for _, f := range p.Funcs {
+ f.IsDeprecated = false
+ }
+ for _, t := range p.Types {
+ t.IsDeprecated = false
+ for _, f := range t.Funcs {
+ f.IsDeprecated = false
+ }
+ for _, m := range t.Methods {
+ m.IsDeprecated = false
+ }
+ }
+ }
+
funcs, data, links := renderInfo(ctx, fset, p, opt)
p = data.Package
if docIsEmpty(p) {
diff --git a/internal/godoc/dochtml/dochtml_test.go b/internal/godoc/dochtml/dochtml_test.go
index af2cb6382..a78027c09 100644
--- a/internal/godoc/dochtml/dochtml_test.go
+++ b/internal/godoc/dochtml/dochtml_test.go
@@ -39,7 +39,7 @@ var testRenderOptions = RenderOptions{
SinceVersionFunc: func(string) string { return "" },
}
-func TestRenderParts(t *testing.T) {
+func TestRender(t *testing.T) {
ctx := context.Background()
LoadTemplates(templateSource)
@@ -50,15 +50,6 @@ func TestRenderParts(t *testing.T) {
}
compareWithGolden(t, parts, "everydecl", *update)
- if experiment.IsActive(ctx, internal.ExperimentDeprecatedDoc) {
- fset2, d2 := mustLoadPackage("deprecated")
- parts2, err := Render(ctx, fset2, d2, testRenderOptions)
- if err != nil {
- t.Fatal(err)
- }
- compareWithGolden(t, parts2, "deprecated", *update)
- }
-
bodyDoc, err := html.Parse(strings.NewReader(parts.Body.String()))
if err != nil {
t.Fatal(err)
@@ -82,6 +73,21 @@ func TestRenderParts(t *testing.T) {
}
}
+func TestRenderDeprecated(t *testing.T) {
+ compare := func(ctx context.Context, name string) {
+ t.Helper()
+ fset, d := mustLoadPackage("deprecated")
+ parts, err := Render(ctx, fset, d, testRenderOptions)
+ if err != nil {
+ t.Fatal(err)
+ }
+ compareWithGolden(t, parts, name, *update)
+ }
+
+ compare(context.Background(), "deprecated-off")
+ compare(experiment.NewContext(context.Background(), internal.ExperimentDeprecatedDoc), "deprecated-on")
+}
+
func compareWithGolden(t *testing.T, parts *Parts, name string, update bool) {
got := fmt.Sprintf("%s\n----\n%s\n----\n%s\n", parts.Body, parts.Outline, parts.MobileOutline)
testhelper.CompareWithGolden(t, got, name+".golden", update)
diff --git a/internal/godoc/dochtml/testdata/deprecated-off.golden b/internal/godoc/dochtml/testdata/deprecated-off.golden
new file mode 100644
index 000000000..cbc7370c1
--- /dev/null
+++ b/internal/godoc/dochtml/testdata/deprecated-off.golden
@@ -0,0 +1,382 @@
+
+
+
+
+Package deprecated has some deprecated symbols.
+
+
+
+
+
+ BadC is bad.
+Deprecated: use GoodC.
+
+
+
+
+
+
+
+
+
+
+ Deprecated: use GoodV.
+
+
+
+
+
+
+
+
+
+
+
+
+
BadF is bad.
+Deprecated: use GoodF.
+
+
+
+
+
+
+
+
+
+
+
BadT is bad.
+Deprecated: use GoodT.
+Don't use this.
+
+
+
+
+
+
+
+
+
+
+
func NewGoodTBad() GoodT
+
+
NewGoodTBad is bad.
+Deprecated: use NewGoodTGood.
+
+
+
+
+
+
+
func NewGoodTGood() GoodT
+
+
+
+
+
+
+
+
BadM is bad.
+Deprecated: use GoodM.
+
+
+
+
+----
+
+
+
+----
+
+
+
+
+
+
+
+
+
+
+
diff --git a/internal/godoc/dochtml/testdata/deprecated.golden b/internal/godoc/dochtml/testdata/deprecated-on.golden
similarity index 54%
rename from internal/godoc/dochtml/testdata/deprecated.golden
rename to internal/godoc/dochtml/testdata/deprecated-on.golden
index dc20332fc..eef9c320c 100644
--- a/internal/godoc/dochtml/testdata/deprecated.golden
+++ b/internal/godoc/dochtml/testdata/deprecated-on.golden
@@ -13,21 +13,43 @@
Constants
Variables
- func GoodF()
-
+ func BadF()deprecated
+
+ func GoodF()
+type BadTdeprecated
type GoodT
+
+ BadC is bad.
+Deprecated: use GoodC.
+
+
View Source
const GoodC = 1
@@ -38,6 +60,15 @@
+
+ Deprecated: use GoodV.
+
+
+
----
@@ -131,6 +210,13 @@
+ -
+
+ BadF()
+
+
+
-
@@ -148,6 +234,16 @@
+ -
+
+ NewGoodTBad()
+
+
+
-
@@ -167,6 +270,13 @@
+ -
+
+ BadM()
+
+
+
-
@@ -205,6 +315,8 @@
@@ -213,11 +325,20 @@
- type A
- type B
- type I1
@@ -25,12 +24,16 @@ attributes.
- type S2
- type T
- Bugs
@@ -62,12 +65,14 @@ attributes.
+
@@ -75,7 +80,8 @@ attributes.
func
-
+
+
@@ -86,6 +92,7 @@ attributes.
+
@@ -97,6 +104,7 @@ attributes.
+
@@ -108,6 +116,7 @@ attributes.
+
type I1 interface {
M1()
@@ -121,6 +130,7 @@ attributes.
+
type I2 interface {
I1
@@ -135,6 +145,7 @@ attributes.
+
type S1 struct {
F int
@@ -148,6 +159,7 @@ attributes.
+
type S2 struct {
S1
@@ -162,6 +174,7 @@ attributes.
+
@@ -186,12 +199,14 @@ attributes.
typeVariable
+
@@ -199,13 +214,16 @@ attributes.
typeFunc
-
+
@@ -214,7 +232,8 @@ attributes.
method
BUG(uid): this verifies that notes are rendered
-
+
+