mirror of
https://github.com/makew0rld/amfora.git
synced 2024-12-04 14:46:29 -05:00
Merge pull request #72 from CosmicToast/relurl
✨ Allow relative URLs in bottom bar
This commit is contained in:
commit
5ea97f3a8f
@ -3,7 +3,6 @@ package display
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -127,27 +126,19 @@ func Init() {
|
|||||||
reset()
|
reset()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if query == ".." && tabs[tab].hasContent() {
|
if query[0] == '.' && tabs[tab].hasContent() {
|
||||||
// Go up a directory
|
// Relative url
|
||||||
parsed, err := url.Parse(tabs[tab].page.Url)
|
current, err := url.Parse(tabs[tab].page.Url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This shouldn't occur
|
// This shouldn't occur
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if parsed.Path == "/" {
|
target, err := current.Parse(query)
|
||||||
// Can't go up further
|
if err != nil {
|
||||||
reset()
|
// Invalid relative url
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
URL(target.String())
|
||||||
// Ex: /test/foo/ -> /test/foo//.. -> /test -> /test/
|
|
||||||
parsed.Path = path.Clean(parsed.Path+"/..") + "/"
|
|
||||||
if parsed.Path == "//" {
|
|
||||||
// Fix double slash that occurs at domain root
|
|
||||||
parsed.Path = "/"
|
|
||||||
}
|
|
||||||
parsed.RawQuery = "" // Remove query
|
|
||||||
URL(parsed.String())
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user