-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpaths.go
53 lines (47 loc) · 1.09 KB
/
paths.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import "strings"
func (a *goBlog) getRelativePath(blog, path string) string {
// Get blog
bc := a.cfg.Blogs[blog]
if bc == nil {
return ""
}
// Get relative path
return bc.getRelativePath(path)
}
func (blog *configBlog) getRelativePath(path string) string {
// Check if path is absolute
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
// Check if blog uses subpath
if blog.Path != "" && blog.Path != "/" {
// Check if path is root
if path == "/" {
path = blog.Path
} else {
path = blog.Path + path
}
}
return path
}
func (a *goBlog) getFullAddress(path string) string {
// Call method with just the relevant config
return a.cfg.Server.getFullAddress(path)
}
func (cfg *configServer) getFullAddress(path string) string {
// Check if it is already an absolute URL
if isAbsoluteURL(path) {
return path
}
// Remove trailing slash
pa := strings.TrimSuffix(cfg.PublicAddress, "/")
// Check if path is root => blank path
if path == "/" {
path = ""
}
return pa + path
}
func (a *goBlog) getInstanceRootURL() string {
return a.getFullAddress("") + "/"
}