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">
<link rel="stylesheet" href="/assets/style.css">
</head>
<body>
<body>`
const navHeader = `
<div>
<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~>
</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>
</div>
</div>
<div id="content">`
`
const contentHeader = `
<div id="content">
`
const inputPrompt = `
<form method="post" action="~GEMINIINPUTFORM~">

View file

@ -61,6 +61,14 @@ func rewriteURL(u string, loc *url.URL) string {
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.
func Convert(page []byte, u string) []byte {
var result []byte
@ -148,7 +156,7 @@ func Convert(page []byte, u string) []byte {
result = append(result, []byte("</pre>\n")...)
}
data := []byte(pageHeader)
data := newPage()
data = append(data, result...)
data = append(data, []byte(pageFooter)...)
return fillTemplateVariables(data, u, false)

View file

@ -115,7 +115,7 @@ func fetch(u string) ([]byte, []byte, error) {
if requestInput {
requestSensitiveInput := bytes.HasPrefix(header, []byte("11"))
data = []byte(pageHeader)
data = newPage()
data = append(data, []byte(inputPrompt)...)
@ -137,7 +137,7 @@ func fetch(u string) ([]byte, []byte, error) {
}
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(pageFooter)...)
return header, fillTemplateVariables(errorPage, u, false), nil
@ -156,8 +156,7 @@ func handleIndex(writer http.ResponseWriter, request *http.Request) {
return
}
var page []byte
page = append(page, pageHeader...)
page := newPage()
page = append(page, bookmarksList()...)
page = append(page, pageFooter...)
@ -289,7 +288,7 @@ func handleBookmarks(writer http.ResponseWriter, request *http.Request) {
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)))...)
@ -312,7 +311,7 @@ func handleBookmarks(writer http.ResponseWriter, request *http.Request) {
RemoveBookmark(deleteBookmark)
}
data = []byte(pageHeader)
data = newPage()
addBookmark := request.FormValue("add")