From 7cb074bfde9c1fc7d73b796900faf414127bb524 Mon Sep 17 00:00:00 2001 From: Will Norris Date: Mon, 25 Apr 2016 15:27:12 -0700 Subject: [PATCH] website: serve /doc/ URLs from top-level doc dir - move existing content from website/content/docs to top-level doc directory - redirect /docs/ URLs to /doc/ Fixes #720 Change-Id: I92e26bbc1fdbe994089080ae3a971d85c12921ab --- .../content/docs/index.html => doc/README.md | 0 website/content/docs/arch => doc/arch.md | 0 .../client-config => doc/client-config.md | 0 .../json-signing/README.md | 0 .../content/docs/overview => doc/overview.md | 0 .../docs/principles => doc/principles.md | 0 .../docs/prior-art => doc/prior-art.md | 0 .../docs/protocol => doc/protocol/README.md | 0 {website/content/docs => doc}/release/0.1 | 0 {website/content/docs => doc}/release/0.2 | 0 {website/content/docs => doc}/release/0.3 | 0 {website/content/docs => doc}/release/0.4 | 0 {website/content/docs => doc}/release/0.5 | 0 {website/content/docs => doc}/release/0.6 | 0 {website/content/docs => doc}/release/0.7 | 0 {website/content/docs => doc}/release/0.8 | 0 {website/content/docs => doc}/release/0.9 | 0 {website/content/docs => doc}/release/log.sh | 0 .../content/docs => doc}/schema/index.html | 0 .../permanode => doc/schema/permanode.md | 0 .../server-config => doc/server-config.md | 0 .../content/docs/sharing => doc/sharing.md | 0 website/content/docs/status => doc/status.md | 0 website/content/docs/terms => doc/terms.md | 0 website/content/docs/todo => doc/todo.md | 0 website/content/docs/uses => doc/uses.md | 0 .../web-ui-styleguide.md | 0 website/camweb.go | 31 +++++++++++++------ 28 files changed, 22 insertions(+), 9 deletions(-) rename website/content/docs/index.html => doc/README.md (100%) rename website/content/docs/arch => doc/arch.md (100%) rename website/content/docs/client-config => doc/client-config.md (100%) rename website/content/docs/json-signing => doc/json-signing/README.md (100%) rename website/content/docs/overview => doc/overview.md (100%) rename website/content/docs/principles => doc/principles.md (100%) rename website/content/docs/prior-art => doc/prior-art.md (100%) rename website/content/docs/protocol => doc/protocol/README.md (100%) rename {website/content/docs => doc}/release/0.1 (100%) rename {website/content/docs => doc}/release/0.2 (100%) rename {website/content/docs => doc}/release/0.3 (100%) rename {website/content/docs => doc}/release/0.4 (100%) rename {website/content/docs => doc}/release/0.5 (100%) rename {website/content/docs => doc}/release/0.6 (100%) rename {website/content/docs => doc}/release/0.7 (100%) rename {website/content/docs => doc}/release/0.8 (100%) rename {website/content/docs => doc}/release/0.9 (100%) rename {website/content/docs => doc}/release/log.sh (100%) rename {website/content/docs => doc}/schema/index.html (100%) rename website/content/docs/schema/permanode => doc/schema/permanode.md (100%) rename website/content/docs/server-config => doc/server-config.md (100%) rename website/content/docs/sharing => doc/sharing.md (100%) rename website/content/docs/status => doc/status.md (100%) rename website/content/docs/terms => doc/terms.md (100%) rename website/content/docs/todo => doc/todo.md (100%) rename website/content/docs/uses => doc/uses.md (100%) rename website/content/docs/web-ui-styleguide => doc/web-ui-styleguide.md (100%) diff --git a/website/content/docs/index.html b/doc/README.md similarity index 100% rename from website/content/docs/index.html rename to doc/README.md diff --git a/website/content/docs/arch b/doc/arch.md similarity index 100% rename from website/content/docs/arch rename to doc/arch.md diff --git a/website/content/docs/client-config b/doc/client-config.md similarity index 100% rename from website/content/docs/client-config rename to doc/client-config.md diff --git a/website/content/docs/json-signing b/doc/json-signing/README.md similarity index 100% rename from website/content/docs/json-signing rename to doc/json-signing/README.md diff --git a/website/content/docs/overview b/doc/overview.md similarity index 100% rename from website/content/docs/overview rename to doc/overview.md diff --git a/website/content/docs/principles b/doc/principles.md similarity index 100% rename from website/content/docs/principles rename to doc/principles.md diff --git a/website/content/docs/prior-art b/doc/prior-art.md similarity index 100% rename from website/content/docs/prior-art rename to doc/prior-art.md diff --git a/website/content/docs/protocol b/doc/protocol/README.md similarity index 100% rename from website/content/docs/protocol rename to doc/protocol/README.md diff --git a/website/content/docs/release/0.1 b/doc/release/0.1 similarity index 100% rename from website/content/docs/release/0.1 rename to doc/release/0.1 diff --git a/website/content/docs/release/0.2 b/doc/release/0.2 similarity index 100% rename from website/content/docs/release/0.2 rename to doc/release/0.2 diff --git a/website/content/docs/release/0.3 b/doc/release/0.3 similarity index 100% rename from website/content/docs/release/0.3 rename to doc/release/0.3 diff --git a/website/content/docs/release/0.4 b/doc/release/0.4 similarity index 100% rename from website/content/docs/release/0.4 rename to doc/release/0.4 diff --git a/website/content/docs/release/0.5 b/doc/release/0.5 similarity index 100% rename from website/content/docs/release/0.5 rename to doc/release/0.5 diff --git a/website/content/docs/release/0.6 b/doc/release/0.6 similarity index 100% rename from website/content/docs/release/0.6 rename to doc/release/0.6 diff --git a/website/content/docs/release/0.7 b/doc/release/0.7 similarity index 100% rename from website/content/docs/release/0.7 rename to doc/release/0.7 diff --git a/website/content/docs/release/0.8 b/doc/release/0.8 similarity index 100% rename from website/content/docs/release/0.8 rename to doc/release/0.8 diff --git a/website/content/docs/release/0.9 b/doc/release/0.9 similarity index 100% rename from website/content/docs/release/0.9 rename to doc/release/0.9 diff --git a/website/content/docs/release/log.sh b/doc/release/log.sh similarity index 100% rename from website/content/docs/release/log.sh rename to doc/release/log.sh diff --git a/website/content/docs/schema/index.html b/doc/schema/index.html similarity index 100% rename from website/content/docs/schema/index.html rename to doc/schema/index.html diff --git a/website/content/docs/schema/permanode b/doc/schema/permanode.md similarity index 100% rename from website/content/docs/schema/permanode rename to doc/schema/permanode.md diff --git a/website/content/docs/server-config b/doc/server-config.md similarity index 100% rename from website/content/docs/server-config rename to doc/server-config.md diff --git a/website/content/docs/sharing b/doc/sharing.md similarity index 100% rename from website/content/docs/sharing rename to doc/sharing.md diff --git a/website/content/docs/status b/doc/status.md similarity index 100% rename from website/content/docs/status rename to doc/status.md diff --git a/website/content/docs/terms b/doc/terms.md similarity index 100% rename from website/content/docs/terms rename to doc/terms.md diff --git a/website/content/docs/todo b/doc/todo.md similarity index 100% rename from website/content/docs/todo rename to doc/todo.md diff --git a/website/content/docs/uses b/doc/uses.md similarity index 100% rename from website/content/docs/uses rename to doc/uses.md diff --git a/website/content/docs/web-ui-styleguide b/doc/web-ui-styleguide.md similarity index 100% rename from website/content/docs/web-ui-styleguide rename to doc/web-ui-styleguide.md diff --git a/website/camweb.go b/website/camweb.go index 513cb7245..3fe23886d 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -68,7 +68,7 @@ var h1TitlePattern = regexp.MustCompile(`

([^<]+)

`) var ( httpAddr = flag.String("http", defaultAddr, "HTTP address") httpsAddr = flag.String("https", "", "HTTPS address") - root = flag.String("root", "", "Website root (parent of 'static', 'content', and 'tmpl") + root = flag.String("root", "", "Website root (parent of 'static', 'content', and 'tmpl)") logDir = flag.String("logdir", "", "Directory to write log files to (one per hour), or empty to not log.") logStdout = flag.Bool("logstdout", true, "Whether to log to stdout") tlsCertFile = flag.String("tlscert", "", "TLS cert file") @@ -228,6 +228,10 @@ func redirectPath(u *url.URL) string { // Assume it's a commit return gerritURLPrefix + path } + + if strings.HasPrefix(u.Path, "/docs/") { + return "/doc/" + strings.TrimPrefix(u.Path, "/docs/") + } return "" } @@ -245,6 +249,10 @@ func mainHandler(rw http.ResponseWriter, req *http.Request) { findAndServeFile(rw, req, filepath.Join(*root, "content")) } +func docHandler(rw http.ResponseWriter, req *http.Request) { + findAndServeFile(rw, req, filepath.Join(filepath.Dir(*root), "doc")) +} + // modtime is the modification time of the resource to be served, or IsZero(). // return value is whether this request is now complete. func checkLastModified(w http.ResponseWriter, r *http.Request, modtime time.Time) bool { @@ -300,18 +308,22 @@ func findAndServeFile(rw http.ResponseWriter, req *http.Request, root string) { for _, index := range []string{"index.html", "README.md"} { absPath = filepath.Join(root, relPath, index) fi, err = os.Lstat(absPath) - if err == nil || !os.IsNotExist(err) { - break - } - if fi.IsDir() { - log.Printf("Error serving website content: %q is a directory", absPath) + if err != nil { + if os.IsNotExist(err) { + // didn't find this file, try the next + continue + } + log.Print(err) + serveError(rw, req, relPath, err) return } + break } } - if err != nil { - log.Print(err) - serveError(rw, req, relPath, err) + + if fi.IsDir() { + log.Printf("Error serving website content: %q is a directory", absPath) + serveError(rw, req, relPath, fmt.Errorf("error: %q is a directory", absPath)) return } @@ -707,6 +719,7 @@ func main() { mux.Handle("/lists", redirTo("/community")) mux.HandleFunc("/contributors", contribHandler()) + mux.Handle("/doc/", http.StripPrefix("/doc", http.HandlerFunc(docHandler))) mux.HandleFunc("/", mainHandler) if *buildbotHost != "" && *buildbotBackend != "" {