internal/middleware: fix inconsistent latest badge
The latest badge is now consistent for a given path, regardlesss of the
module path for the path. This allows the badge to be consistent across
multi-module projects.
Fixes golang/go#41032
Change-Id: Ib8105d72c87dd323e011d0a93599f7b69a9e508a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/277697
Run-TryBot: Julie Qiu <julie@golang.org>
TryBot-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Jamal Carvalho <jamal@golang.org>
Trust: Julie Qiu <julie@golang.org>
diff --git a/internal/frontend/server_test.go b/internal/frontend/server_test.go
index c9f1895..2f2982d 100644
--- a/internal/frontend/server_test.go
+++ b/internal/frontend/server_test.go
@@ -559,7 +559,7 @@
FormattedVersion: "v0.4.0",
LicenseType: "MIT",
LicenseFilePath: "LICENSE",
- IsLatestMinor: true,
+ IsLatestMinor: false,
IsLatestMajor: true,
UnitURLFormat: "/cloud.google.com/go/pubsublite%s",
LatestLink: "/cloud.google.com/go/pubsublite",
diff --git a/internal/middleware/latestversion.go b/internal/middleware/latestversion.go
index c492684..1953b12 100644
--- a/internal/middleware/latestversion.go
+++ b/internal/middleware/latestversion.go
@@ -12,6 +12,7 @@
"strings"
"golang.org/x/mod/module"
+ "golang.org/x/pkgsite/internal"
"golang.org/x/pkgsite/internal/log"
)
@@ -47,7 +48,7 @@
_, majorVersion, _ := module.SplitPathVersion(modulePath)
packagePath := string(matches[3])
pageType := string(matches[4])
- latestMinorVersion := latestMinor(r.Context(), packagePath, modulePath, pageType)
+ latestMinorVersion := latestMinor(r.Context(), packagePath, internal.UnknownModulePath, pageType)
latestMinorClass := "DetailsHeader-badge"
switch {
case latestMinorVersion == "":
@@ -57,6 +58,7 @@
default:
latestMinorClass += "--goToLatest"
}
+
latestModulePath, latestPackagePath := latestMajor(r.Context(), packagePath, modulePath)
_, latestMajorVersion, ok := module.SplitPathVersion(latestModulePath)
var latestMajorVersionText string