diff --git a/pkg/gmitohtml/assets.go b/pkg/gmitohtml/assets.go index 3d7b736..61ec424 100644 --- a/pkg/gmitohtml/assets.go +++ b/pkg/gmitohtml/assets.go @@ -9,16 +9,22 @@ const pageHeader = ` - +` + +const navHeader = `
- -
` +` + +const contentHeader = ` +
+` const inputPrompt = `
diff --git a/pkg/gmitohtml/convert.go b/pkg/gmitohtml/convert.go index ba24b23..549df8e 100644 --- a/pkg/gmitohtml/convert.go +++ b/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("\n")...) } - data := []byte(pageHeader) + data := newPage() data = append(data, result...) data = append(data, []byte(pageFooter)...) return fillTemplateVariables(data, u, false) diff --git a/pkg/gmitohtml/daemon.go b/pkg/gmitohtml/daemon.go index 6656640..57eb3a4 100644 --- a/pkg/gmitohtml/daemon.go +++ b/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:

%s", 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(`

Edit bookmark





`, 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")