From 8bbe5ccb71b7dea0bb814decc80e7a2e53edf07d Mon Sep 17 00:00:00 2001 From: Andrew Gerrand Date: Fri, 20 Jan 2012 07:37:36 +1100 Subject: [PATCH] godoc: support canonical Paths in HTML metadata Redirect to the canonical path when the old path is accessed. R=gri CC=golang-dev https://golang.org/cl/5536061 --- doc/docs.html | 3 +- doc/root.html | 4 + src/cmd/godoc/godoc.go | 170 +++++++++++++++++++++++++++++++++-------- src/cmd/godoc/main.go | 3 + 4 files changed, 147 insertions(+), 33 deletions(-) diff --git a/doc/docs.html b/doc/docs.html index c0ced98de4e..e99017fca0e 100644 --- a/doc/docs.html +++ b/doc/docs.html @@ -1,5 +1,6 @@
diff --git a/doc/root.html b/doc/root.html index 635df1a0525..23a35eb8440 100644 --- a/doc/root.html +++ b/doc/root.html @@ -1,3 +1,7 @@ + + diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go index 61a3142ff62..06da96b0fb6 100644 --- a/src/cmd/godoc/godoc.go +++ b/src/cmd/godoc/godoc.go @@ -74,12 +74,13 @@ var ( indexThrottle = flag.Float64("index_throttle", 0.75, "index throttle value; 0.0 = no time allocated, 1.0 = full throttle") // file system mapping - fs FileSystem // the underlying file system for godoc - fsHttp http.FileSystem // the underlying file system for http - fsMap Mapping // user-defined mapping - fsTree RWValue // *Directory tree of packages, updated with each sync - pathFilter RWValue // filter used when building fsMap directory trees - fsModified RWValue // timestamp of last call to invalidateIndex + fs FileSystem // the underlying file system for godoc + fsHttp http.FileSystem // the underlying file system for http + fsMap Mapping // user-defined mapping + fsTree RWValue // *Directory tree of packages, updated with each sync + pathFilter RWValue // filter used when building fsMap directory trees + fsModified RWValue // timestamp of last call to invalidateIndex + docMetadata RWValue // mapping from paths to *Metadata // http handlers fileServer http.Handler // default file server @@ -698,11 +699,6 @@ var ( jsonEnd = []byte("}-->") ) -type Metadata struct { - Title string - Subtitle string -} - func serveHTMLDoc(w http.ResponseWriter, r *http.Request, abspath, relpath string) { // get HTML body contents src, err := ReadFile(fs, abspath) @@ -720,15 +716,9 @@ func serveHTMLDoc(w http.ResponseWriter, r *http.Request, abspath, relpath strin } // if it begins with a JSON blob, read in the metadata. - var meta Metadata - if bytes.HasPrefix(src, jsonStart) { - if end := bytes.Index(src, jsonEnd); end > -1 { - b := src[len(jsonStart)-1 : end+1] // drop leading