Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to save about: pages. #236

Merged
merged 4 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion display/bookmarks.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func addBookmark() {
t := tabs[curTab]
p := t.page

if !t.hasContent() {
if !t.hasContent() || t.isAnAboutPage() {
// It's an about: page, or a malformed one
return
}
Expand Down
2 changes: 1 addition & 1 deletion display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Init(version, commit, builtBy string) {
reset()
return
}
if query[0] == '.' && tabs[tab].hasContent() {
if query[0] == '.' && tabs[tab].hasContent() && !tabs[tab].isAnAboutPage() {
// Relative url
current, err := url.Parse(tabs[tab].page.URL)
if err != nil {
Expand Down
9 changes: 8 additions & 1 deletion display/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,14 @@ func downloadPage(p *structs.Page) (string, error) {
func downloadNameFromURL(dir, u, ext string) (string, error) {
var name string
var err error

parsed, _ := url.Parse(u)
if parsed.Path == "" || path.Base(parsed.Path) == "/" {
if strings.HasPrefix(u, "about:") {
name, err = getSafeDownloadName(dir, parsed.Opaque+ext, true, 0)
if err != nil {
return "", err
}
} else if parsed.Path == "" || path.Base(parsed.Path) == "/" {
// No file, just the root domain
name, err = getSafeDownloadName(dir, parsed.Hostname()+ext, true, 0)
if err != nil {
Expand All @@ -340,6 +346,7 @@ func downloadNameFromURL(dir, u, ext string) (string, error) {
return "", err
}
}

return filepath.Join(dir, name), nil
}

Expand Down
2 changes: 1 addition & 1 deletion display/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
t.mode = tabModeDone

go func(p *structs.Page) {
if b && t.hasContent() && viper.GetBool("subscriptions.popup") {
if b && t.hasContent() && !t.isAnAboutPage() && viper.GetBool("subscriptions.popup") {
// The current page might be an untracked feed, and the user wants
// to be notified in such cases.

Expand Down
2 changes: 1 addition & 1 deletion display/private.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func followLink(t *tab, prev, next string) {
return
}

if t.hasContent() {
if t.hasContent() && !t.isAnAboutPage() {
nextURL, err := resolveRelLink(t, prev, next)
if err != nil {
Error("URL Error", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion display/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func addSubscription() {
t := tabs[curTab]
p := t.page

if !t.hasContent() {
if !t.hasContent() || t.isAnAboutPage() {
// It's an about: page, or a malformed one
return
}
Expand Down
10 changes: 6 additions & 4 deletions display/tab.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,25 @@ func (t *tab) pageDown() {
}

// hasContent returns false when the tab's page is malformed,
// has no content or URL, or if it's an 'about:' page.
// has no content or URL.
func (t *tab) hasContent() bool {
if t.page == nil || t.view == nil {
return false
}
if t.page.URL == "" {
return false
}
if strings.HasPrefix(t.page.URL, "about:") {
return false
}
if t.page.Content == "" {
return false
}
return true
}

// isAnAboutPage returns true when the tab's page is an about page
func (t *tab) isAnAboutPage() bool {
return strings.HasPrefix(t.page.URL, "about:")
}

// applyHorizontalScroll handles horizontal scroll logic including left margin resizing,
// see #197 for details. Use applyScroll instead.
//
Expand Down
2 changes: 1 addition & 1 deletion display/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func textWidth() int {
// It also returns an error if it could not resolve the links, which should be displayed
// to the user.
func resolveRelLink(t *tab, prev, next string) (string, error) {
if !t.hasContent() {
if !t.hasContent() || t.isAnAboutPage() {
return next, nil
}

Expand Down