forked from sloum/bombadillo
Merge pull request 'Reworks how relative URLs are handled for gemini' (#153) from pathing-fixes into release-2.3.0
This commit is contained in:
commit
c34226e4c1
19
client.go
19
client.go
|
@ -977,8 +977,10 @@ func (c *client) handleGemini(u Url) {
|
|||
go saveConfig()
|
||||
switch capsule.Status {
|
||||
case 1:
|
||||
// Query
|
||||
c.search("", u.Full, capsule.Content)
|
||||
case 2:
|
||||
// Success
|
||||
if capsule.MimeMaj == "text" || (c.Options["showimages"] == "true" && capsule.MimeMaj == "image") {
|
||||
pg := MakePage(u, capsule.Content, capsule.Links)
|
||||
pg.FileType = capsule.MimeMaj
|
||||
|
@ -996,14 +998,21 @@ func (c *client) handleGemini(u Url) {
|
|||
c.saveFileFromData(capsule.Content, filename)
|
||||
}
|
||||
case 3:
|
||||
c.SetMessage(fmt.Sprintf("Follow redirect? (y/n): %s", capsule.Content), false)
|
||||
c.DrawMessage()
|
||||
ch := cui.Getch()
|
||||
if ch == 'y' || ch == 'Y' {
|
||||
// Redirect
|
||||
lowerRedirect := strings.ToLower(capsule.Content)
|
||||
lowerOriginal := strings.ToLower(u.Full)
|
||||
if strings.Replace(lowerRedirect, lowerOriginal, "", 1) == "/" {
|
||||
c.Visit(capsule.Content)
|
||||
} else {
|
||||
c.SetMessage("Redirect aborted", false)
|
||||
c.SetMessage(fmt.Sprintf("Follow redirect (y/n): %s?", capsule.Content), false)
|
||||
c.DrawMessage()
|
||||
ch := cui.Getch()
|
||||
if ch == 'y' || ch == 'Y' {
|
||||
c.Visit(capsule.Content)
|
||||
} else {
|
||||
c.SetMessage("Redirect aborted", false)
|
||||
c.DrawMessage()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -409,18 +409,38 @@ func handleRelativeUrl(u, root, current string) string {
|
|||
if len(u) < 1 {
|
||||
return u
|
||||
}
|
||||
currentIsDir := (current[len(current)-1] == '/')
|
||||
|
||||
if u[0] == '/' {
|
||||
return fmt.Sprintf("%s%s", root, u)
|
||||
} else if strings.HasPrefix(u, "../") {
|
||||
currentDir := strings.LastIndex(current, "/")
|
||||
if currentIsDir {
|
||||
upOne := strings.LastIndex(current[:currentDir], "/")
|
||||
dirRoot := current[:upOne]
|
||||
return dirRoot + u[2:]
|
||||
}
|
||||
return current[:currentDir] + u[2:]
|
||||
}
|
||||
|
||||
if strings.HasPrefix(u, "./") {
|
||||
if len(u) == 2 {
|
||||
return current
|
||||
}
|
||||
u = u[2:]
|
||||
}
|
||||
|
||||
if currentIsDir {
|
||||
indPrevDir := strings.LastIndex(current[:len(current)-1], "/")
|
||||
if indPrevDir < 9 {
|
||||
return current + u
|
||||
}
|
||||
return current[:indPrevDir+1] + u
|
||||
}
|
||||
|
||||
ind := strings.LastIndex(current, "/")
|
||||
if ind < 10 {
|
||||
return fmt.Sprintf("%s/%s", root, u)
|
||||
}
|
||||
|
||||
current = current[:ind+1]
|
||||
return fmt.Sprintf("%s%s", current, u)
|
||||
return current + u
|
||||
}
|
||||
|
||||
func hashCert(cert []byte) string {
|
||||
|
|
Loading…
Reference in New Issue