godoc: fix source links for cmd/*
Fixes golang/go#12159 Change-Id: Id498443171cbdf0fe9808745a79edc863d836db1 Reviewed-on: https://go-review.googlesource.com/14001 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
1330b289ad
commit
31971b7521
|
@ -266,6 +266,18 @@ func testWeb(t *testing.T, withIndex bool) {
|
||||||
},
|
},
|
||||||
needIndex: true,
|
needIndex: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/pkg/strings/",
|
||||||
|
match: []string{
|
||||||
|
`href="/src/strings/strings.go"`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: "/cmd/compile/internal/amd64/",
|
||||||
|
match: []string{
|
||||||
|
`href="/src/cmd/compile/internal/amd64/reg.go"`,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
if test.needIndex && !withIndex {
|
if test.needIndex && !withIndex {
|
||||||
|
|
|
@ -119,14 +119,15 @@ func NewPresentation(c *Corpus) *Presentation {
|
||||||
p: p,
|
p: p,
|
||||||
c: c,
|
c: c,
|
||||||
pattern: "/cmd/",
|
pattern: "/cmd/",
|
||||||
fsRoot: "/src/cmd",
|
fsRoot: "/src",
|
||||||
}
|
}
|
||||||
p.pkgHandler = handlerServer{
|
p.pkgHandler = handlerServer{
|
||||||
p: p,
|
p: p,
|
||||||
c: c,
|
c: c,
|
||||||
pattern: "/pkg/",
|
pattern: "/pkg/",
|
||||||
fsRoot: "/src",
|
stripPrefix: "pkg/",
|
||||||
exclude: []string{"/src/cmd"},
|
fsRoot: "/src",
|
||||||
|
exclude: []string{"/src/cmd"},
|
||||||
}
|
}
|
||||||
p.cmdHandler.registerWithMux(p.mux)
|
p.cmdHandler.registerWithMux(p.mux)
|
||||||
p.pkgHandler.registerWithMux(p.mux)
|
p.pkgHandler.registerWithMux(p.mux)
|
||||||
|
|
|
@ -34,11 +34,12 @@ import (
|
||||||
// handlerServer is a migration from an old godoc http Handler type.
|
// handlerServer is a migration from an old godoc http Handler type.
|
||||||
// This should probably merge into something else.
|
// This should probably merge into something else.
|
||||||
type handlerServer struct {
|
type handlerServer struct {
|
||||||
p *Presentation
|
p *Presentation
|
||||||
c *Corpus // copy of p.Corpus
|
c *Corpus // copy of p.Corpus
|
||||||
pattern string // url pattern; e.g. "/pkg/"
|
pattern string // url pattern; e.g. "/pkg/"
|
||||||
fsRoot string // file system root to which the pattern is mapped; e.g. "/src"
|
stripPrefix string // prefix to strip from import path; e.g. "pkg/"
|
||||||
exclude []string // file system paths to exclude; e.g. "/src/cmd"
|
fsRoot string // file system root to which the pattern is mapped; e.g. "/src"
|
||||||
|
exclude []string // file system paths to exclude; e.g. "/src/cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *handlerServer) registerWithMux(mux *http.ServeMux) {
|
func (s *handlerServer) registerWithMux(mux *http.ServeMux) {
|
||||||
|
@ -235,7 +236,7 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
relpath := pathpkg.Clean(r.URL.Path[len(h.pattern):])
|
relpath := pathpkg.Clean(r.URL.Path[len(h.stripPrefix)+1:])
|
||||||
abspath := pathpkg.Join(h.fsRoot, relpath)
|
abspath := pathpkg.Join(h.fsRoot, relpath)
|
||||||
mode := h.p.GetPageInfoMode(r)
|
mode := h.p.GetPageInfoMode(r)
|
||||||
if relpath == builtinPkgPath {
|
if relpath == builtinPkgPath {
|
||||||
|
|
Loading…
Reference in New Issue