diff options
Diffstat (limited to 'cmd/blog/blog.go')
-rw-r--r-- | cmd/blog/blog.go | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/cmd/blog/blog.go b/cmd/blog/blog.go index 87de9b8..e6a8feb 100644 --- a/cmd/blog/blog.go +++ b/cmd/blog/blog.go @@ -7,15 +7,45 @@ package main import ( - "code.google.com/p/go.blog/pkg/blog" + "net/http" + "strings" + "time" + + "code.google.com/p/go.tools/godoc/blog" + "code.google.com/p/go.tools/godoc/static" + _ "code.google.com/p/go.tools/godoc/playground" ) const hostname = "blog.golang.org" // default hostname for blog server -var config = &blog.Config{ +var config = blog.Config{ Hostname: hostname, BaseURL: "http://" + hostname, + GodocURL: "http://golang.org", HomeArticles: 5, // articles to display on the home page FeedArticles: 10, // articles to include in Atom and JSON feeds + PlayEnabled: true, +} + +func init() { + // Redirect "/blog/" to "/", because the menu bar link is to "/blog/" + // but we're serving from the root. + redirect := func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/", http.StatusFound) + } + http.HandleFunc("/blog", redirect) + http.HandleFunc("/blog/", redirect) + + http.Handle("/lib/godoc/", http.StripPrefix("/lib/godoc/", http.HandlerFunc(staticHandler))) +} + +func staticHandler(w http.ResponseWriter, r *http.Request) { + name := r.URL.Path + b, ok := static.Files[name] + if !ok { + http.NotFound(w, r) + return + } + http.ServeContent(w, r, name, time.Time{}, strings.NewReader(b)) } |