diff --git a/godoc/godoc.go b/godoc/godoc.go index 5c6d9820..d6c27d0b 100644 --- a/godoc/godoc.go +++ b/godoc/godoc.go @@ -461,17 +461,14 @@ func pkgLinkFunc(path string) string { return "pkg/" + path } -// srcToPkgLinkFunc builds an tag linking to -// the package documentation of relpath. +// srcToPkgLinkFunc builds an tag linking to the package +// documentation of relpath. func srcToPkgLinkFunc(relpath string) string { relpath = pkgLinkFunc(relpath) - if relpath == "pkg/" { + relpath = pathpkg.Dir(relpath) + if relpath == "pkg" { return `Index` } - if i := strings.LastIndex(relpath, "/"); i != -1 { - // Remove filename after last slash. - relpath = relpath[:i] - } return fmt.Sprintf(`%s`, relpath, relpath[len("pkg/"):]) } diff --git a/godoc/godoc_test.go b/godoc/godoc_test.go index dca1c951..c1d631c1 100644 --- a/godoc/godoc_test.go +++ b/godoc/godoc_test.go @@ -313,6 +313,8 @@ func TestSrcToPkgLinkFunc(t *testing.T) { }{ {"src/", `Index`}, {"src/fmt/", `fmt`}, + {"pkg/", `Index`}, + {"pkg/LICENSE", `Index`}, } { if got := srcToPkgLinkFunc(tc.path); got != tc.want { t.Errorf("srcToPkgLinkFunc(%v) = %v; want %v", tc.path, got, tc.want)