diff --git a/bebop/browser.py b/bebop/browser.py index b2d8856..aa093cc 100644 --- a/bebop/browser.py +++ b/bebop/browser.py @@ -113,6 +113,8 @@ class Browser: self.go_back() elif char == ord("u"): self.go_to_parent_page() + elif char == ord("U"): + self.go_to_root_page() elif curses.ascii.isdigit(char): self.handle_digit_input(char) elif char == curses.KEY_MOUSE: @@ -470,6 +472,11 @@ class Browser: if self.current_url: self.open_gemini_url(get_parent_url(self.current_url)) + def go_to_root_page(self): + """Go to the root URL if possible.""" + if self.current_url: + self.open_gemini_url(get_root_url(self.current_url)) + def open_web_url(self, url): """Open a Web URL. Currently relies in Python's webbrowser module.""" self.set_status(f"Opening {url}") diff --git a/bebop/navigation.py b/bebop/navigation.py index 799b7c9..35cb96d 100644 --- a/bebop/navigation.py +++ b/bebop/navigation.py @@ -58,3 +58,9 @@ def get_parent_url(url: str) -> str: if last_slash > -1: path = path[:last_slash + 1] return urllib.parse.urlunparse((scheme, netloc, path, params, query, frag)) + + +def get_root_url(url: str) -> str: + """Return the root URL (basically discards path).""" + scheme, netloc, _, _, _, _ = parse_url(url) + return urllib.parse.urlunparse((scheme, netloc, "/", "", "", ""))