Browse Source

Do not display address bar when running without daemon

pull/5/head
Trevor Slocum 11 months ago
parent
commit
2a1abe8efe
  1. 12
      pkg/gmitohtml/assets.go
  2. 10
      pkg/gmitohtml/convert.go
  3. 11
      pkg/gmitohtml/daemon.go

12
pkg/gmitohtml/assets.go

@ -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~">

10
pkg/gmitohtml/convert.go

@ -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)

11
pkg/gmitohtml/daemon.go

@ -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")

Loading…
Cancel
Save