diff options
Diffstat (limited to 'handlers.go')
| -rw-r--r-- | handlers.go | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/handlers.go b/handlers.go index e68c5f5..b4ce3f2 100644 --- a/handlers.go +++ b/handlers.go @@ -12,12 +12,13 @@ import ( "tildegit.org/tjp/sliderule/gemini/gemtext" "tildegit.org/tjp/sliderule/gopher" "tildegit.org/tjp/sliderule/gopher/gophermap" + "tildegit.org/tjp/sliderule/spartan" ) func docType(u *url.URL, response *sliderule.Response) string { _, gopherType := gopherURL(u) switch gopherType { - case gopher.MenuType: + case gopher.MenuType, gopher.SearchType: return "text/x-gophermap" case gopher.TextFileType, gopher.ErrorType, gopher.InfoMessageType: return "text/plain" @@ -49,18 +50,26 @@ func docType(u *url.URL, response *sliderule.Response) string { return "application/xml" } - if u.Scheme == "gemini" { - if response.Status == gemini.StatusSuccess { - mtype, _, err := mime.ParseMediaType(response.Meta.(string)) - if err == nil { - return mtype - } + if metaIsMediaType(u, response) { + mtype, _, err := mime.ParseMediaType(response.Meta.(string)) + if err == nil { + return mtype } } return "text/plain" } +func metaIsMediaType(u *url.URL, response *sliderule.Response) bool { + if u.Scheme == "gemini" && response.Status == gemini.StatusSuccess { + return true + } + if u.Scheme == "spartan" && response.Status == spartan.StatusSuccess { + return true + } + return false +} + func parseDoc(doctype string, body []byte, conf *Config) (string, []Link, error) { switch doctype { case "text/x-gophermap": @@ -114,7 +123,11 @@ func parseGemtextDoc(body []byte, softWrap int) (string, []Link, error) { i := 0 for _, item := range gemdoc { + isPrompt := false switch item.Type() { + case gemtext.LineTypePrompt: + isPrompt = true + fallthrough case gemtext.LineTypeLink: ll := item.(gemtext.LinkLine) u, err := url.Parse(ll.URL()) @@ -124,6 +137,7 @@ func parseGemtextDoc(body []byte, softWrap int) (string, []Link, error) { l = append(l, Link{ Text: ll.Label(), Target: u, + Prompt: isPrompt, }) label := ll.Label() if len(label) == 0 { |
