diff options
| author | Fuwn <[email protected]> | 2022-02-22 00:50:51 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-02-22 00:50:51 +0000 |
| commit | 318702156c77daf20bfa878949214411ac976443 (patch) | |
| tree | e25c2ad6bd6cb4518f16252cbde6d3e1c94f9502 /capybara.go | |
| parent | Merge remote-tracking branch 'upstream/master' (diff) | |
| download | capybara-318702156c77daf20bfa878949214411ac976443.tar.xz capybara-318702156c77daf20bfa878949214411ac976443.zip | |
feat(#2): optionally, do not proxy url(s)
If the user provides a `Capybara.yaml` with the `capybara.keep_gemini`
key, do not proxy the provided values (URLs).
Also implements a rudimentary configuration system for future extension.
Thanks, @WellsBit!
Diffstat (limited to 'capybara.go')
| -rw-r--r-- | capybara.go | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/capybara.go b/capybara.go index 497ffe5..b60d728 100644 --- a/capybara.go +++ b/capybara.go @@ -17,8 +17,24 @@ import ( "git.sr.ht/~adnano/go-gemini" "git.sr.ht/~sircmpwn/getopt" + "github.com/spf13/viper" ) +var keepGeminiLinks []string + +func init() { + viper.SetConfigName("Capybara.yaml") + viper.SetConfigType("yaml") + viper.AddConfigPath("./") + viper.AddConfigPath(".capybara/") + viper.AddConfigPath(".capybara-data/") + viper.AddConfigPath("/app/.capybara/") + + if err := viper.ReadInConfig(); err == nil { + keepGeminiLinks = viper.GetStringSlice("capybara.keep_gemini") + } +} + var gemtextPage = template.Must(template. New("gemtext"). Funcs(template.FuncMap{ @@ -108,11 +124,20 @@ var gemtextPage = template.Must(template. u = ctx.URL.ResolveReference(u) if u.Scheme == "" || u.Scheme == "gemini" { - if u.Host != ctx.Root.Host { - u.Path = fmt.Sprintf("/proxy/%s%s", u.Host, u.Path) + keepGemini := false + for _, v := range keepGeminiLinks { + if v == u.Host { + keepGemini = true + } + } + + if !keepGemini { + if u.Host != ctx.Root.Host { + u.Path = fmt.Sprintf("/proxy/%s%s", u.Host, u.Path) + } + u.Scheme = "" + u.Host = "" } - u.Scheme = "" - u.Host = "" } return template.URL(u.String()) }, |