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:
Andrew Gerrand 2015-08-28 11:00:04 +10:00
parent 1330b289ad
commit 31971b7521
3 changed files with 26 additions and 12 deletions

View File

@ -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 {

View File

@ -119,12 +119,13 @@ 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/",
stripPrefix: "pkg/",
fsRoot: "/src", fsRoot: "/src",
exclude: []string{"/src/cmd"}, exclude: []string{"/src/cmd"},
} }

View File

@ -37,6 +37,7 @@ 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/"
stripPrefix string // prefix to strip from import path; e.g. "pkg/"
fsRoot string // file system root to which the pattern is mapped; e.g. "/src" 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" exclude []string // file system paths to exclude; e.g. "/src/cmd"
} }
@ -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 {