Compare commits

...

5 Commits

Author SHA1 Message Date
Andrew Bonventre 3b2b05e9f5 [release-branch.go1.8] godoc: add GoogleCN property to pages
Use that property to determine whether to show share functionality
or link to sites that are blocked in mainland China.

This change requires https://go-review.googlesource.com/c/52872

Change-Id: I47327f9dbd2624206564fa99eb1cc6a10b4f46db
Reviewed-on: https://go-review.googlesource.com/52873
Reviewed-by: Chris Broadfoot <cbro@golang.org>
Reviewed-on: https://go-review.googlesource.com/81075
Reviewed-by: Russ Cox <rsc@golang.org>
2017-11-30 21:11:23 +00:00
Andrew Bonventre 77187f3c2d [release-branch.go1.8] x/tools/godoc: fix redirect to Gerrit
Redirects to /r/NNNN broke due to crbug.com/gerrit/6888.
Alternative URLs are available in the meantime: /NNNN and /c/NNNN.
This change uses the /NNNN format.

Fixes golang/go#21235

Change-Id: Ie30e01bedd7a8277aedd4070b5f82a754521ed03
Reviewed-on: https://go-review.googlesource.com/52150
Reviewed-by: Kevin Burke <kev@inburke.com>
Reviewed-on: https://go-review.googlesource.com/52170
Reviewed-by: Andrew Bonventre <andybons@golang.org>
2017-07-31 17:59:59 +00:00
Gerrit Code Review 5682db0e91 Merge "[release-branch.go1.8] all: merge master into release-branch.go1.8" into release-branch.go1.8 2017-01-26 20:51:04 +00:00
Chris Broadfoot 9f028c45f3 [release-branch.go1.8] all: merge master into release-branch.go1.8
f8ed2e40 cmd/guru: fix typo of 'hyphen' to rename to 'comma'
61efd711 godoc: fix quadratic and ASCII-only struct field linkification
721f2184 imports: remove unnecessary string conversion
fcfba28e go/internal/gccgoimporter: support for type aliases
add1aac0 static: don't use the jQuery func for looking up based on hash
608c3b09 present: fix typo
0d047c8d cmd/godex: handle printing of type aliases
de557280 go/gcimporter15: update import/export to handle type aliases
5d76f8ce static: detect platform to hide/show unix/windows instructions

Change-Id: If3753b030500781b5bf086e56485e75343744799
2017-01-26 10:47:28 -08:00
Chris Broadfoot 8187b5f3e6 [release-branch.go1.8] all: merge master into release-branch.go1.8
add1aac0 static: don't use the jQuery func for looking up based on hash
608c3b09 present: fix typo
0d047c8d cmd/godex: handle printing of type aliases
de557280 go/gcimporter15: update import/export to handle type aliases
5d76f8ce static: detect platform to hide/show unix/windows instructions

Change-Id: I327abdef58298a72d2c2cdcd24da6bfd096bd262
2017-01-19 12:44:55 -08:00
10 changed files with 43 additions and 29 deletions

View File

@ -10,7 +10,7 @@ binary. It can be tedious to recompile assets every time, but you can pass a
flag to load CSS/JS/templates from disk every time a page loads:
```
godoc --templates=$GOPATH/src/golang.org/x/tools/godoc/static --http=:6060
godoc -templates=$GOPATH/src/golang.org/x/tools/godoc/static -http=:6060
```
## Recompiling static assets

View File

@ -438,9 +438,9 @@ func sanitizeFunc(src string) string {
}
type PageInfo struct {
Dirname string // directory containing the package
Err error // error or nil
Share bool // show share button on examples
Dirname string // directory containing the package
Err error // error or nil
GoogleCN bool // page is being served from golang.google.cn
// package info
FSet *token.FileSet // nil if no package documentation
@ -650,8 +650,8 @@ func (p *Presentation) example_htmlFunc(info *PageInfo, funcName string) string
err := p.ExampleHTML.Execute(&buf, struct {
Name, Doc, Code, Play, Output string
Share bool
}{eg.Name, eg.Doc, code, play, out, info.Share})
GoogleCN bool
}{eg.Name, eg.Doc, code, play, out, info.GoogleCN})
if err != nil {
log.Print(err)
}

View File

@ -9,6 +9,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"
)
// Page describes the contents of the top-level godoc webpage.
@ -18,7 +19,7 @@ type Page struct {
Subtitle string
Query string
Body []byte
Share bool
GoogleCN bool // page is being served from golang.google.cn
// filled in by servePage
SearchBox bool
@ -50,19 +51,25 @@ func (p *Presentation) ServeError(w http.ResponseWriter, r *http.Request, relpat
Title: "File " + relpath,
Subtitle: relpath,
Body: applyTemplate(p.ErrorHTML, "errorHTML", err),
Share: allowShare(r),
GoogleCN: googleCN(r),
})
}
var onAppengine = false // overriden in appengine.go when on app engine
var onAppengine = false // overridden in appengine.go when on app engine
func allowShare(r *http.Request) bool {
func googleCN(r *http.Request) bool {
if r.FormValue("googlecn") != "" {
return true
}
if !onAppengine {
return false
}
if strings.HasSuffix(r.Host, ".cn") {
return true
}
switch r.Header.Get("X-AppEngine-Country") {
case "", "ZZ", "CN":
return false
return true
}
return true
return false
}

View File

@ -19,6 +19,7 @@ import (
"net/http"
"net/http/httputil"
"net/url"
"strings"
"time"
"golang.org/x/net/context"
@ -147,8 +148,8 @@ func cacheKey(body string) string {
}
func share(w http.ResponseWriter, r *http.Request) {
if !allowShare(r) {
http.Error(w, "Forbidden", http.StatusForbidden)
if googleCN(r) {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}
target, _ := url.Parse(playgroundURL)
@ -157,13 +158,19 @@ func share(w http.ResponseWriter, r *http.Request) {
p.ServeHTTP(w, r)
}
func allowShare(r *http.Request) bool {
func googleCN(r *http.Request) bool {
if r.FormValue("googlecn") != "" {
return true
}
if appengine.IsDevAppServer() {
return false
}
if strings.HasSuffix(r.Host, ".cn") {
return true
}
switch r.Header.Get("X-AppEngine-Country") {
case "", "ZZ", "CN":
return false
return true
}
return true
return false
}

View File

@ -196,7 +196,7 @@ func clHandler(w http.ResponseWriter, r *http.Request) {
if n, err := strconv.Atoi(id); err == nil && n > 150000 {
target = "https://codereview.appspot.com/" + id
} else {
target = "https://go-review.googlesource.com/r/" + id
target = "https://go-review.googlesource.com/" + id
}
http.Redirect(w, r, target, http.StatusFound)
}

View File

@ -55,8 +55,8 @@ func TestRedirects(t *testing.T) {
"/design/123-foo": {302, "https://github.com/golang/proposal/blob/master/design/123-foo.md"},
"/design/text/123-foo": {302, "https://github.com/golang/proposal/blob/master/design/text/123-foo.md"},
"/cl/1": {302, "https://go-review.googlesource.com/r/1"},
"/cl/1/": {302, "https://go-review.googlesource.com/r/1"},
"/cl/1": {302, "https://go-review.googlesource.com/1"},
"/cl/1/": {302, "https://go-review.googlesource.com/1"},
"/cl/267120043": {302, "https://codereview.appspot.com/267120043"},
"/cl/267120043/": {302, "https://codereview.appspot.com/267120043"},
}

View File

@ -126,7 +126,7 @@ func (p *Presentation) HandleSearch(w http.ResponseWriter, r *http.Request) {
Tabtitle: query,
Query: query,
Body: body.Bytes(),
Share: allowShare(r),
GoogleCN: googleCN(r),
})
}

View File

@ -307,13 +307,13 @@ func (h *handlerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
info.TypeInfoIndex[ti.Name] = i
}
info.Share = allowShare(r)
info.GoogleCN = googleCN(r)
h.p.ServePage(w, Page{
Title: title,
Tabtitle: tabtitle,
Subtitle: subtitle,
Body: applyTemplate(h.p.PackageHTML, "packageHTML", info),
Share: info.Share,
GoogleCN: info.GoogleCN,
})
}
@ -555,7 +555,7 @@ func (p *Presentation) serveTextFile(w http.ResponseWriter, r *http.Request, abs
Title: title + " " + relpath,
Tabtitle: relpath,
Body: buf.Bytes(),
Share: allowShare(r),
GoogleCN: googleCN(r),
})
}
@ -616,7 +616,7 @@ func (p *Presentation) serveDirectory(w http.ResponseWriter, r *http.Request, ab
Title: "Directory " + relpath,
Tabtitle: relpath,
Body: applyTemplate(p.DirlistHTML, "dirlistHTML", list),
Share: allowShare(r),
GoogleCN: googleCN(r),
})
}
@ -645,7 +645,7 @@ func (p *Presentation) ServeHTMLDoc(w http.ResponseWriter, r *http.Request, absp
page := Page{
Title: meta.Title,
Subtitle: meta.Subtitle,
Share: allowShare(r),
GoogleCN: googleCN(r),
}
// evaluate as template if indicated

View File

@ -13,7 +13,7 @@
<div class="buttons">
<a class="run" title="Run this code [shift-enter]">Run</a>
<a class="fmt" title="Format this code">Format</a>
{{if $.Share}}
{{if not $.GoogleCN}}
<a class="share" title="Share this code">Share</a>
{{end}}
</div>

View File

@ -55,7 +55,7 @@ func main() {
<div class="buttons">
<a class="run" title="Run this code [shift-enter]">Run</a>
<a class="fmt" title="Format this code">Format</a>
{{if $.Share}}
{{if not $.GoogleCN}}
<a class="share" title="Share this code">Share</a>
{{end}}
</div>
@ -85,7 +85,7 @@ Except as <a href="https://developers.google.com/site-policies#restrictions">not
the content of this page is licensed under the
Creative Commons Attribution 3.0 License,
and code is licensed under a <a href="/LICENSE">BSD license</a>.<br>
<a href="/doc/tos.html">Terms of Service</a> |
<a href="/doc/tos.html">Terms of Service</a> |
<a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
</div>