From 318702156c77daf20bfa878949214411ac976443 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Tue, 22 Feb 2022 00:50:51 +0000 Subject: 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! --- capybara.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'capybara.go') 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()) }, -- cgit v1.2.3