Rewrite links to subpackage import paths
This commit is contained in:
parent
6387f68699
commit
fdf6456c43
|
@ -1,3 +1,6 @@
|
|||
0.1.4:
|
||||
- Rewrite links to subpackage import paths
|
||||
|
||||
0.1.3:
|
||||
- Add --exclude flag
|
||||
- Fix compilation on Windows
|
||||
|
|
29
page.go
29
page.go
|
@ -60,7 +60,34 @@ func updatePage(doc *goquery.Document, basePath string, siteName string) {
|
|||
importPathDisplayText := importPathDisplay.Text()
|
||||
if strings.ContainsRune(importPathDisplayText, '.') && strings.HasPrefix(importPathDisplayText, `import "`) && strings.HasSuffix(importPathDisplayText, `"`) {
|
||||
importPath := importPathDisplayText[8 : len(importPathDisplayText)-1]
|
||||
importPathDisplay.SetHtml(fmt.Sprintf(`import "<a href="https://` + importPath + `" target="_blank">` + importPath + `</a>"`))
|
||||
|
||||
browseImportPath := importPath
|
||||
var browseInsert string
|
||||
if strings.HasPrefix(importPath, "gitlab.com/") {
|
||||
browseInsert = "/-/tree/master"
|
||||
} else if strings.HasPrefix(importPath, "github.com/") || strings.HasPrefix(importPath, "git.sr.ht/") {
|
||||
browseInsert = "/tree/master"
|
||||
} else if strings.HasPrefix(importPath, "bitbucket.org/") {
|
||||
browseInsert = "/src/master"
|
||||
}
|
||||
if browseInsert != "" {
|
||||
var insertPos int
|
||||
var found int
|
||||
for i, c := range importPath {
|
||||
if c == '/' {
|
||||
found++
|
||||
if found == 3 {
|
||||
insertPos = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if insertPos > 0 {
|
||||
browseImportPath = importPath[0:insertPos] + browseInsert + importPath[insertPos:]
|
||||
}
|
||||
}
|
||||
|
||||
importPathDisplay.SetHtml(fmt.Sprintf(`import "<a href="https://` + browseImportPath + `" target="_blank">` + importPath + `</a>"`))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue