From a44a063c1a60ca11066d21d49aca95cfed7d3499 Mon Sep 17 00:00:00 2001 From: tjp Date: Tue, 9 Jan 2024 09:53:15 -0700 Subject: mimetype handling upon general navigation: 1. check for any configured handlers for the mimetype 2. normal printing for gophermap, gemtext, and text/plain 3. save the file to downloads folder --- actions.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'actions.go') diff --git a/actions.go b/actions.go index 28713ee..448ac06 100644 --- a/actions.go +++ b/actions.go @@ -8,6 +8,7 @@ import ( "net/url" "os" "os/exec" + "path" "path/filepath" "strconv" "strings" @@ -176,7 +177,7 @@ func Reload(state *BrowserState, conf *Config) error { return err } - return print(state) + return HandleResource(state, conf) } func externalMessage() ([]byte, error) { @@ -470,6 +471,23 @@ func Print(state *BrowserState) error { return print(state) } +func HandleResource(state *BrowserState, conf *Config) error { + if state.Modal != nil { + return Print(state) + } + + if handler, ok := conf.Handlers[state.DocType]; ok { + return Pipe(state, handler) + } + + switch state.DocType { + case "text/gemini", "text/x-gophermap", "text/plain": + return print(state) + } + + return Save(state, path.Base(state.Url.Path), conf) +} + func Outline(state *BrowserState, conf *Config) error { if state.Body == nil { return ErrMustBeOnAPage -- cgit v1.2.3