mirror of
https://github.com/golang/go
synced 2024-09-24 19:20:13 -06:00
godoc: use shorter titles for tabs
In a browser with many open tabs, the tab titles become short and uninformative because they all start with the same prefix ("Package ", "Directory ", etc.). Permit use of shorter tab titles that start with the relevant information first. Fixes #3365. R=golang-dev, bradfitz CC=golang-dev https://golang.org/cl/5865056
This commit is contained in:
parent
e2662835b8
commit
cfd8b84f07
@ -2,7 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
{{with .Title}}
|
{{with .Tabtitle}}
|
||||||
<title>{{html .}} - The Go Programming Language</title>
|
<title>{{html .}} - The Go Programming Language</title>
|
||||||
{{else}}
|
{{else}}
|
||||||
<title>The Go Programming Language</title>
|
<title>The Go Programming Language</title>
|
||||||
|
@ -69,7 +69,7 @@ func codewalk(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
b := applyTemplate(codewalkHTML, "codewalk", cw)
|
b := applyTemplate(codewalkHTML, "codewalk", cw)
|
||||||
servePage(w, "Codewalk: "+cw.Title, "", "", b)
|
servePage(w, cw.Title, "Codewalk: "+cw.Title, "", "", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Codewalk represents a single codewalk read from an XML file.
|
// A Codewalk represents a single codewalk read from an XML file.
|
||||||
@ -200,7 +200,7 @@ func codewalkDir(w http.ResponseWriter, r *http.Request, relpath, abspath string
|
|||||||
}
|
}
|
||||||
|
|
||||||
b := applyTemplate(codewalkdirHTML, "codewalkdir", v)
|
b := applyTemplate(codewalkdirHTML, "codewalkdir", v)
|
||||||
servePage(w, "Codewalks", "", "", b)
|
servePage(w, "", "Codewalks", "", "", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// codewalkFileprint serves requests with ?fileprint=f&lo=lo&hi=hi.
|
// codewalkFileprint serves requests with ?fileprint=f&lo=lo&hi=hi.
|
||||||
|
@ -546,8 +546,12 @@ func readTemplates() {
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Generic HTML wrapper
|
// Generic HTML wrapper
|
||||||
|
|
||||||
func servePage(w http.ResponseWriter, title, subtitle, query string, content []byte) {
|
func servePage(w http.ResponseWriter, tabtitle, title, subtitle, query string, content []byte) {
|
||||||
|
if tabtitle == "" {
|
||||||
|
tabtitle = title
|
||||||
|
}
|
||||||
d := struct {
|
d := struct {
|
||||||
|
Tabtitle string
|
||||||
Title string
|
Title string
|
||||||
Subtitle string
|
Subtitle string
|
||||||
SearchBox bool
|
SearchBox bool
|
||||||
@ -556,6 +560,7 @@ func servePage(w http.ResponseWriter, title, subtitle, query string, content []b
|
|||||||
Menu []byte
|
Menu []byte
|
||||||
Content []byte
|
Content []byte
|
||||||
}{
|
}{
|
||||||
|
tabtitle,
|
||||||
title,
|
title,
|
||||||
subtitle,
|
subtitle,
|
||||||
*indexEnabled,
|
*indexEnabled,
|
||||||
@ -630,7 +635,7 @@ func serveHTMLDoc(w http.ResponseWriter, r *http.Request, abspath, relpath strin
|
|||||||
src = buf.Bytes()
|
src = buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
servePage(w, meta.Title, meta.Subtitle, "", src)
|
servePage(w, "", meta.Title, meta.Subtitle, "", src)
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
|
func applyTemplate(t *template.Template, name string, data interface{}) []byte {
|
||||||
@ -666,7 +671,7 @@ func serveTextFile(w http.ResponseWriter, r *http.Request, abspath, relpath, tit
|
|||||||
FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s")))
|
FormatText(&buf, src, 1, pathpkg.Ext(abspath) == ".go", r.FormValue("h"), rangeSelection(r.FormValue("s")))
|
||||||
buf.WriteString("</pre>")
|
buf.WriteString("</pre>")
|
||||||
|
|
||||||
servePage(w, title+" "+relpath, "", "", buf.Bytes())
|
servePage(w, relpath, title+" "+relpath, "", "", buf.Bytes())
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveDirectory(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
|
func serveDirectory(w http.ResponseWriter, r *http.Request, abspath, relpath string) {
|
||||||
@ -681,7 +686,7 @@ func serveDirectory(w http.ResponseWriter, r *http.Request, abspath, relpath str
|
|||||||
}
|
}
|
||||||
|
|
||||||
contents := applyTemplate(dirlistHTML, "dirlistHTML", list)
|
contents := applyTemplate(dirlistHTML, "dirlistHTML", list)
|
||||||
servePage(w, "Directory "+relpath, "", "", contents)
|
servePage(w, relpath, "Directory "+relpath, "", "", contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveFile(w http.ResponseWriter, r *http.Request) {
|
func serveFile(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -1073,30 +1078,41 @@ func (h *docServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var title, subtitle string
|
var tabtitle, title, subtitle string
|
||||||
switch {
|
switch {
|
||||||
case info.PAst != nil:
|
case info.PAst != nil:
|
||||||
title = "Package " + info.PAst.Name.Name
|
tabtitle = info.PAst.Name.Name
|
||||||
|
title = "Package " + tabtitle
|
||||||
case info.PDoc != nil:
|
case info.PDoc != nil:
|
||||||
switch {
|
if info.PDoc.Name == fakePkgName {
|
||||||
case info.IsPkg:
|
|
||||||
title = "Package " + info.PDoc.Name
|
|
||||||
case info.PDoc.Name == fakePkgName:
|
|
||||||
// assume that the directory name is the command name
|
// assume that the directory name is the command name
|
||||||
_, pkgname := pathpkg.Split(relpath)
|
_, tabtitle = pathpkg.Split(relpath)
|
||||||
title = "Command " + pkgname
|
} else {
|
||||||
default:
|
tabtitle = info.PDoc.Name
|
||||||
title = "Command " + info.PDoc.Name
|
}
|
||||||
|
if info.IsPkg {
|
||||||
|
title = "Package " + tabtitle
|
||||||
|
} else {
|
||||||
|
title = "Command " + tabtitle
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
title = "Directory " + info.Dirname
|
tabtitle = info.Dirname
|
||||||
|
title = "Directory " + tabtitle
|
||||||
if *showTimestamps {
|
if *showTimestamps {
|
||||||
subtitle = "Last update: " + info.DirTime.String()
|
subtitle = "Last update: " + info.DirTime.String()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// special cases for top-level package/command directories
|
||||||
|
switch tabtitle {
|
||||||
|
case "/src/pkg":
|
||||||
|
tabtitle = "Packages"
|
||||||
|
case "/src/cmd":
|
||||||
|
tabtitle = "Commands"
|
||||||
|
}
|
||||||
|
|
||||||
contents := applyTemplate(packageHTML, "packageHTML", info)
|
contents := applyTemplate(packageHTML, "packageHTML", info)
|
||||||
servePage(w, title, subtitle, "", contents)
|
servePage(w, tabtitle, title, subtitle, "", contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -1186,7 +1202,7 @@ func search(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
contents := applyTemplate(searchHTML, "searchHTML", result)
|
contents := applyTemplate(searchHTML, "searchHTML", result)
|
||||||
servePage(w, title, "", query, contents)
|
servePage(w, query, title, "", query, contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -73,7 +73,7 @@ var (
|
|||||||
func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
|
func serveError(w http.ResponseWriter, r *http.Request, relpath string, err error) {
|
||||||
contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path!
|
contents := applyTemplate(errorHTML, "errorHTML", err) // err may contain an absolute path!
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusNotFound)
|
||||||
servePage(w, "File "+relpath, "", "", contents)
|
servePage(w, relpath, "File "+relpath, "", "", contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
func usage() {
|
func usage() {
|
||||||
|
Loading…
Reference in New Issue
Block a user