From 035fca1208d46033dc347fded52ea8279e1880a2 Mon Sep 17 00:00:00 2001 From: makeworld Date: Thu, 24 Dec 2020 16:25:39 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Don't=20use=20cache=20when=20URL?= =?UTF-8?q?=20is=20typed=20in=20bottom=20bar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #159 --- CHANGELOG.md | 2 ++ display/display.go | 12 +++++------- display/util.go | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index df88b76..91109a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Ability to set custom keybindings in config (#135) +### Fixed +- Don't use cache when URL is typed in bottom bar (#159) ## [1.7.2] - 2020-12-21 ### Fixed diff --git a/display/display.go b/display/display.go index ffc8b17..b3d448a 100644 --- a/display/display.go +++ b/display/display.go @@ -206,11 +206,13 @@ func Init(version, commit, builtBy string) { // Then it's a search u := viper.GetString("a-general.search") + "?" + gemini.QueryEscape(query) - cache.RemovePage(u) // Don't use the cached version of the search + // Don't use the cached version of the search + cache.RemovePage(normalizeURL(u)) URL(u) } else { // Full URL - cache.RemovePage(query) // Don't use cached version for manually entered URL + // Don't use cached version for manually entered URL + cache.RemovePage(normalizeURL(fixUserURL(query))) URL(query) } return @@ -572,11 +574,7 @@ func URL(u string) { return } - if !strings.HasPrefix(u, "//") && !strings.HasPrefix(u, "gemini://") && !strings.Contains(u, "://") { - // Assume it's a Gemini URL - u = "gemini://" + u - } - go goURL(t, u) + go goURL(t, fixUserURL(u)) } func NumTabs() int { diff --git a/display/util.go b/display/util.go index 7c3d19c..33495c1 100644 --- a/display/util.go +++ b/display/util.go @@ -127,3 +127,17 @@ func normalizeURL(u string) string { return parsed.String() } + +// fixUserURL will take a user-typed URL and add a gemini scheme to it if +// necessary. It is not the same as normalizeURL, and that func should still +// be used, afterward. +// +// For example "example.com" will become "gemini://example.com", but +// "//example.com" will be left untouched. +func fixUserURL(u string) string { + if !strings.HasPrefix(u, "//") && !strings.HasPrefix(u, "gemini://") && !strings.Contains(u, "://") { + // Assume it's a Gemini URL + u = "gemini://" + u + } + return u +}