forked from tslocum/godoc-static
Add builtin package support, bug fixes and cleanup
parent
715940234c
commit
a60b3c33ef
22
main.go
22
main.go
|
@ -95,12 +95,12 @@ PACKAGEINDEX:
|
|||
if pkg == excludePackage || strings.HasPrefix(pkg, excludePackage+"/") {
|
||||
continue PACKAGEINDEX
|
||||
}
|
||||
}
|
||||
|
||||
if !disableFilter {
|
||||
for _, skipPackage := range skipPackages {
|
||||
if strings.Contains(pkg, "/"+skipPackage+"/") || strings.HasSuffix(pkg, "/"+skipPackage) {
|
||||
continue PACKAGEINDEX
|
||||
}
|
||||
if !disableFilter {
|
||||
for _, skipPackage := range skipPackages {
|
||||
if strings.Contains("/"+pkg+"/", "/"+skipPackage+"/") {
|
||||
continue PACKAGEINDEX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -290,6 +290,18 @@ func run() error {
|
|||
pkgs = strings.Split(strings.TrimSpace(buf.String()), "\n")
|
||||
}
|
||||
|
||||
//include the 'builtin' package as well if not already present
|
||||
isBuiltin := false
|
||||
for _, pkg := range pkgs {
|
||||
if pkg == "builtin" {
|
||||
isBuiltin = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !isBuiltin {
|
||||
pkgs = append(pkgs, "builtin")
|
||||
}
|
||||
|
||||
var newPkgs []string
|
||||
pkgPaths := make(map[string]string)
|
||||
for _, pkg := range pkgs {
|
||||
|
|
43
page.go
43
page.go
|
@ -114,38 +114,29 @@ func updatePage(doc *goquery.Document, basePath string, siteName string) {
|
|||
|
||||
doc.Find("a").Each(func(_ int, selection *goquery.Selection) {
|
||||
href := selection.AttrOr("href", "")
|
||||
if strings.HasPrefix(href, "/src/") || strings.HasPrefix(href, "/pkg/") {
|
||||
if strings.ContainsRune(path.Base(href), '.') {
|
||||
queryPos := strings.IndexRune(href, '?')
|
||||
if queryPos >= 0 {
|
||||
href = href[0:queryPos] + ".html" + href[queryPos:]
|
||||
} else {
|
||||
hashPos := strings.IndexRune(href, '#')
|
||||
if hashPos >= 0 {
|
||||
href = href[0:hashPos] + ".html" + href[hashPos:]
|
||||
} else {
|
||||
href += ".html"
|
||||
}
|
||||
}
|
||||
} else if linkIndex {
|
||||
queryPos := strings.IndexRune(href, '?')
|
||||
if queryPos >= 0 {
|
||||
href = href[0:queryPos] + "/index.html" + href[queryPos:]
|
||||
} else {
|
||||
hashPos := strings.IndexRune(href, '#')
|
||||
if hashPos >= 0 {
|
||||
href = href[0:hashPos] + "/index.html" + href[hashPos:]
|
||||
} else {
|
||||
href += "/index.html"
|
||||
}
|
||||
}
|
||||
|
||||
var suffix string
|
||||
if (strings.HasPrefix(href, "/src/") || strings.HasPrefix(href, "/pkg/")) && path.Ext(href) != "" {
|
||||
suffix = ".html"
|
||||
} else if linkIndex && !(strings.HasPrefix(href, "#") || strings.HasPrefix(href, "?")) && path.Ext(href) == "" {
|
||||
suffix = "/index.html"
|
||||
}
|
||||
if suffix != "" {
|
||||
pos := strings.IndexAny(href, "?#")
|
||||
if pos >= 0 {
|
||||
href = strings.TrimRight(href[0:pos], "/") + suffix + href[pos:]
|
||||
} else {
|
||||
href = strings.TrimRight(href, "/") + suffix
|
||||
}
|
||||
}
|
||||
|
||||
if strings.HasPrefix(href, "/src/") || strings.HasPrefix(href, "/pkg/") {
|
||||
if strings.HasPrefix(href, "/pkg/") {
|
||||
href = href[4:]
|
||||
}
|
||||
|
||||
selection.SetAttr("href", basePath+href[1:])
|
||||
} else if suffix != ""{
|
||||
selection.SetAttr("href", href)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue