summaryrefslogtreecommitdiff
path: root/actions.go
diff options
context:
space:
mode:
authortjp <tjp@ctrl-c.club>2024-01-09 09:53:15 -0700
committertjp <tjp@ctrl-c.club>2024-01-09 09:53:15 -0700
commita44a063c1a60ca11066d21d49aca95cfed7d3499 (patch)
tree65bcb597fd77e27a2c93ca10ce06a0add80d9384 /actions.go
parent15214b7c98cbe77bddb2a52e0849abdfa7953747 (diff)
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
Diffstat (limited to 'actions.go')
-rw-r--r--actions.go20
1 files changed, 19 insertions, 1 deletions
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