diff --git a/website/camweb.go b/website/camweb.go index 40c4f98dd..53d56063d 100644 --- a/website/camweb.go +++ b/website/camweb.go @@ -177,13 +177,22 @@ func applyTemplate(t *template.Template, name string, data interface{}) []byte { return buf.Bytes() } +// goGetDomain returns one of the two domains that we serve for the "go-import" +// meta header +func goGetDomain(host string) string { + if host == "camlistore.org" { + return host + } + return "perkeep.org" +} + type pageParams struct { title string // required subtitle string // used by pkg doc content []byte // required } -func servePage(w http.ResponseWriter, params pageParams) { +func servePage(w http.ResponseWriter, r *http.Request, params pageParams) { title, subtitle, content := params.title, params.subtitle, params.content // insert an "install command" if it applies if strings.Contains(title, cmdPattern) && subtitle != cmdPattern { @@ -197,12 +206,15 @@ func servePage(w http.ResponseWriter, params pageParams) { Title string Subtitle string Content template.HTML + Domain string // for the "go-import" meta header }{ title, subtitle, template.HTML(content), + // the redirects happening before should ensure that r.Host is only ever one of + // camlistore.org or perkeep.org + goGetDomain(r.Host), } - if err := pageHTML.ExecuteTemplate(w, "page", &d); err != nil { log.Printf("godocHTML.Execute: %s", err) } @@ -232,7 +244,7 @@ func readTemplates() { func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) { contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path! w.WriteHeader(http.StatusNotFound) - servePage(w, pageParams{ + servePage(w, r, pageParams{ title: "File " + relpath, content: contents, }) @@ -440,7 +452,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, relPath, absPath string) title = string(m[1]) } - servePage(w, pageParams{ + servePage(w, r, pageParams{ title: title, content: data, }) @@ -467,6 +479,12 @@ func (h *redirectRootHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) return } + if goget := r.FormValue("go-get"); goget == "1" { + // do not redirect on a go get request, because we want to be able to serve the + // "go-import" meta for camlistore.org, and not just for perkeep.org + h.Handler.ServeHTTP(rw, r) + return + } host := strings.ToLower(r.Host) if host == "www.camlistore.org" || host == "camlistore.org" || host == "www."+prodDomain || (inProd && r.TLS == nil) { @@ -1177,7 +1195,7 @@ func errHandler(w http.ResponseWriter, r *http.Request) { } contents := applyTemplate(camliErrorHTML, "camliErrorHTML", data) w.WriteHeader(http.StatusFound) - servePage(w, pageParams{ + servePage(w, r, pageParams{ title: errString, content: contents, }) diff --git a/website/contributors.go b/website/contributors.go index fe1927731..e34a3d9f7 100644 --- a/website/contributors.go +++ b/website/contributors.go @@ -187,7 +187,7 @@ func contribHandler() http.HandlerFunc { title = string(m[1]) } return func(w http.ResponseWriter, r *http.Request) { - servePage(w, pageParams{ + servePage(w, r, pageParams{ title: title, content: c, }) diff --git a/website/godoc.go b/website/godoc.go index 0cfce3b1f..40a6591fc 100644 --- a/website/godoc.go +++ b/website/godoc.go @@ -415,7 +415,7 @@ func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit buf.WriteString("
") FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s"))) buf.WriteString("") - servePage(w, pageParams{ + servePage(w, r, pageParams{ title: title, content: buf.Bytes(), }) @@ -466,7 +466,7 @@ func (godocHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { subtitle := pathpkg.Base(diskPath) title := subtitle + " (" + pathpkg.Join(domainName, suffix) + ")" - servePage(w, pageParams{ + servePage(w, r, pageParams{ title: title, subtitle: subtitle, content: applyTextTemplate(packageHTML, "packageHTML", pi), diff --git a/website/tmpl/page.html b/website/tmpl/page.html index 33bca101e..49fc6223f 100644 --- a/website/tmpl/page.html +++ b/website/tmpl/page.html @@ -16,7 +16,7 @@ {{define "header"}} - + {{with $x := .Title}}