Do not display address bar when running without daemon

This commit is contained in:
Trevor Slocum 2020-12-03 10:42:39 -08:00
parent dd70c77b18
commit 2a1abe8efe
3 changed files with 23 additions and 10 deletions

View file

@ -9,16 +9,22 @@ const pageHeader = `
<meta name="viewport" content="width=device-width,initial-scale=1"> <meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="/assets/style.css"> <link rel="stylesheet" href="/assets/style.css">
</head> </head>
<body> <body>`
const navHeader = `
<div> <div>
<form method="post" action="/" novalidate> <form method="post" action="/" novalidate>
<input type="url" name="address" id="navigationaddress" placeholder="Address" size="40" value="~GEMINICURRENTURL~" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" ~GEMINIAUTOFOCUS~> <input type="url" name="address" id="navigationaddress" placeholder="Address" size="40" value="~GEMINICURRENTURL~" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" ~GEMINIAUTOFOCUS~>
</form> </form>
<div id="navigationbar""> <div id="navigationbar">
<a href="/bookmarks" class="navlink">View bookmarks</a> &nbsp;-&nbsp; <a href="/bookmarks?add=~GEMINICURRENTURL~" class="navlink">Add bookmark</a> <a href="/bookmarks" class="navlink">View bookmarks</a> &nbsp;-&nbsp; <a href="/bookmarks?add=~GEMINICURRENTURL~" class="navlink">Add bookmark</a>
</div> </div>
</div> </div>
<div id="content">` `
const contentHeader = `
<div id="content">
`
const inputPrompt = ` const inputPrompt = `
<form method="post" action="~GEMINIINPUTFORM~"> <form method="post" action="~GEMINIINPUTFORM~">

View file

@ -61,6 +61,14 @@ func rewriteURL(u string, loc *url.URL) string {
return u return u
} }
func newPage() []byte {
data := []byte(pageHeader)
if daemonAddress != "" {
data = append(data, navHeader...)
}
return append(data, contentHeader...)
}
// Convert converts text/gemini to text/html. // Convert converts text/gemini to text/html.
func Convert(page []byte, u string) []byte { func Convert(page []byte, u string) []byte {
var result []byte var result []byte
@ -148,7 +156,7 @@ func Convert(page []byte, u string) []byte {
result = append(result, []byte("</pre>\n")...) result = append(result, []byte("</pre>\n")...)
} }
data := []byte(pageHeader) data := newPage()
data = append(data, result...) data = append(data, result...)
data = append(data, []byte(pageFooter)...) data = append(data, []byte(pageFooter)...)
return fillTemplateVariables(data, u, false) return fillTemplateVariables(data, u, false)

View file

@ -115,7 +115,7 @@ func fetch(u string) ([]byte, []byte, error) {
if requestInput { if requestInput {
requestSensitiveInput := bytes.HasPrefix(header, []byte("11")) requestSensitiveInput := bytes.HasPrefix(header, []byte("11"))
data = []byte(pageHeader) data = newPage()
data = append(data, []byte(inputPrompt)...) data = append(data, []byte(inputPrompt)...)
@ -137,7 +137,7 @@ func fetch(u string) ([]byte, []byte, error) {
} }
if !bytes.HasPrefix(header, []byte("2")) { if !bytes.HasPrefix(header, []byte("2")) {
errorPage := []byte(pageHeader) errorPage := newPage()
errorPage = append(errorPage, []byte(fmt.Sprintf("Server sent unexpected header:<br><br><b>%s</b>", header))...) errorPage = append(errorPage, []byte(fmt.Sprintf("Server sent unexpected header:<br><br><b>%s</b>", header))...)
errorPage = append(errorPage, []byte(pageFooter)...) errorPage = append(errorPage, []byte(pageFooter)...)
return header, fillTemplateVariables(errorPage, u, false), nil return header, fillTemplateVariables(errorPage, u, false), nil
@ -156,8 +156,7 @@ func handleIndex(writer http.ResponseWriter, request *http.Request) {
return return
} }
var page []byte page := newPage()
page = append(page, pageHeader...)
page = append(page, bookmarksList()...) page = append(page, bookmarksList()...)
page = append(page, pageFooter...) page = append(page, pageFooter...)
@ -289,7 +288,7 @@ func handleBookmarks(writer http.ResponseWriter, request *http.Request) {
return return
} }
data = []byte(pageHeader) data = newPage()
data = append(data, []byte(fmt.Sprintf(`<form method="post" action="%s"><h3>Edit bookmark</h3><input type="text" size="40" name="address" placeholder="Address" value="%s" autofocus><br><br><input type="text" size="40" name="label" placeholder="Label" value="%s"><br><br><input type="submit" value="Update"></form>`, request.URL.Path+"?"+request.URL.RawQuery, html.EscapeString(editBookmark), html.EscapeString(label)))...) data = append(data, []byte(fmt.Sprintf(`<form method="post" action="%s"><h3>Edit bookmark</h3><input type="text" size="40" name="address" placeholder="Address" value="%s" autofocus><br><br><input type="text" size="40" name="label" placeholder="Label" value="%s"><br><br><input type="submit" value="Update"></form>`, request.URL.Path+"?"+request.URL.RawQuery, html.EscapeString(editBookmark), html.EscapeString(label)))...)
@ -312,7 +311,7 @@ func handleBookmarks(writer http.ResponseWriter, request *http.Request) {
RemoveBookmark(deleteBookmark) RemoveBookmark(deleteBookmark)
} }
data = []byte(pageHeader) data = newPage()
addBookmark := request.FormValue("add") addBookmark := request.FormValue("add")