diff --git a/CHANGELOG b/CHANGELOG index 8da6a6f6c795dc55bddc89fdce8b0a49ff43acc8..aacca03f4563e5261d4e038f27c8f245b251f595 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,2 +1,5 @@ +0.1.1: +- Link import path + 0.1.0: - Initial release diff --git a/README.md b/README.md index 0bc40918e70938b75f8ffe93130cf10581f91579..057ef8439134d3fecba7480aa519394035c3b933 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # godoc-static -[![GoDoc](https://gitlab.com/tslocum/godoc-static/raw/master/badge.svg)](https://docs.rocketnine.space/gitlab.com/tslocum/godoc-static) [![CI status](https://gitlab.com/tslocum/godoc-static/badges/master/pipeline.svg)](https://gitlab.com/tslocum/godoc-static/commits/master) [![Donate](https://img.shields.io/liberapay/receives/rocketnine.space.svg?logo=liberapay)](https://liberapay.com/rocketnine.space) diff --git a/page.go b/page.go index 5e60b8c2e1feb1cef89285e211f7666db87bec87..4640d04fb00281cd03ab2656686d2c45d2f3326a 100644 --- a/page.go +++ b/page.go @@ -53,6 +53,16 @@ func updatePage(doc *goquery.Document, basePath string, siteName string) { doc.Find("#topbar").First().SetHtml(topBar(basePath, siteName)) + importPathDisplay := doc.Find("#short-nav").First().Find("code").First() + if importPathDisplay.Length() > 0 { + 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 "` + importPath + `"`)) + log.Println(importPathDisplay.Text()) + } + } + doc.Find("a").Each(func(_ int, selection *goquery.Selection) { href := selection.AttrOr("href", "") if strings.HasPrefix(href, "/src/") || strings.HasPrefix(href, "/pkg/") { @@ -116,18 +126,6 @@ func updatePage(doc *goquery.Document, basePath string, siteName string) { } }) - scriptTag := &html.Node{ - Type: html.ElementNode, - DataAtom: atom.Script, - Data: "script", - Attr: []html.Attribute{ - {Key: "type", Val: "text/javascript"}, - {Key: "src", Val: basePath + "lib/godoc-static.js"}, - }, - } - - doc.Find("body").AppendNodes(scriptTag) - doc.Find("#footer").Last().Remove() } @@ -137,9 +135,8 @@ func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName stri index = "/index.html" } - var b bytes.Buffer - - b.WriteString(` + buf.Reset() + buf.WriteString(` @@ -160,10 +157,10 @@ func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName stri `) if siteDescription != "" { - b.WriteString(siteDescription) + buf.WriteString(siteDescription) } - b.WriteString(` + buf.WriteString(`

Packages

@@ -177,14 +174,15 @@ func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName stri var padding int var lastPkg string + var pkgBuf bytes.Buffer for _, pkg := range pkgs { - buf.Reset() + pkgBuf.Reset() listCmd := exec.Command("go", "list", "-find", "-f", `{{ .Doc }}`, pkg) listCmd.Dir = os.TempDir() listCmd.SysProcAttr = &syscall.SysProcAttr{ Pdeathsig: syscall.SIGKILL, } - listCmd.Stdout = buf + listCmd.Stdout = &pkgBuf _ = listCmd.Run() // Ignore error @@ -211,32 +209,31 @@ func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName stri break } } - b.WriteString(` + buf.WriteString(` `) if !linkPackage { - b.WriteString(pkgLabel) + buf.WriteString(pkgLabel) } else { - b.WriteString(`` + pkgLabel + ``) + buf.WriteString(`` + pkgLabel + ``) } - b.WriteString(` + buf.WriteString(` - ` + buf.String() + ` + ` + pkgBuf.String() + ` `) } - b.WriteString(` + buf.WriteString(` - `) - err := ioutil.WriteFile(path.Join(outDir, "index.html"), b.Bytes(), 0755) + err := ioutil.WriteFile(path.Join(outDir, "index.html"), buf.Bytes(), 0755) if err != nil { log.Fatalf("failed to write index: %s", err) }