Commit 6387f686 authored by Trevor Slocum's avatar Trevor Slocum

Add --exclude flag and fix compilation on Windows

parent 658b6bd3
Pipeline #115929849 passed with stages
in 2 minutes and 26 seconds
0.1.3:
- Add --exclude flag
- Fix compilation on Windows
0.1.2:
- Copy all source file types
......
......@@ -12,11 +12,15 @@ Generate static Go documentation
Install `godoc-static`:
`go get gitlab.com/tslocum/godoc-static`
```bash
go get gitlab.com/tslocum/godoc-static
```
Also install `godoc`:
`go get golang.org/x/tools/cmd/godoc`
```bash
go get golang.org/x/tools/cmd/godoc
```
## Documentation
......@@ -26,11 +30,21 @@ Execute `godoc-static` with the `-help` flag for more information.
Generate documentation for `archive`, `fmt` and `net/http` targeting `https://docs.rocketnine.space`:
`godoc-static -base-path=/ -site-name="Rocket Nine Labs Documentation" -site-description="Welcome!" -out=/home/user/sites/docs archive fmt net/http`
```bash
godoc-static -base-path=/ -site-name="Rocket Nine Labs Documentation" \
-site-description="Welcome!" \
-out=/home/user/sites/docs \
archive fmt net/http
```
Targeting `https://rocketnine.space/docs/`:
`godoc-static -base-path=/docs/ -site-name="Rocket Nine Labs Documentation" -site-description-file=/home/user/sitefiles/description.md -out=/home/user/sites/docs archive fmt net/http`
```bash
godoc-static -base-path=/docs/ -site-name="Rocket Nine Labs Documentation" \
-site-description-file=/home/user/sitefiles/description.md \
-out=/home/user/sites/docs \
archive fmt net/http
```
## Support
......
//+build !linux
package main
import "os/exec"
func setDeathSignal(cmd *exec.Cmd) {}
//+build linux
package main
import (
"os/exec"
"syscall"
)
func setDeathSignal(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
}
This diff is collapsed.
......@@ -4,20 +4,22 @@ import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"strconv"
"strings"
"syscall"
"github.com/PuerkitoBio/goquery"
"golang.org/x/net/html"
"golang.org/x/net/html/atom"
"github.com/PuerkitoBio/goquery"
)
const additionalCSS = `
details { margin-top: 20px; }
summary { margin-left: 20px; cursor: pointer; }
`
func topBar(basePath string, siteName string) string {
var index string
if linkIndex {
......@@ -128,7 +130,7 @@ func updatePage(doc *goquery.Document, basePath string, siteName string) {
doc.Find("#footer").Last().Remove()
}
func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName string, pkgs []string, filterPkgs []string) {
func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName string, pkgs []string, filterPkgs []string) error {
var index string
if linkIndex {
index = "/index.html"
......@@ -174,16 +176,22 @@ func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName stri
var padding int
var lastPkg string
var pkgBuf bytes.Buffer
excludePackagesSplit := strings.Split(excludePackages, " ")
PACKAGEINDEX:
for _, pkg := range pkgs {
pkgBuf.Reset()
listCmd := exec.Command("go", "list", "-find", "-f", `{{ .Doc }}`, pkg)
listCmd.Dir = os.TempDir()
listCmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
for _, excludePackage := range excludePackagesSplit {
if pkg == excludePackage || strings.HasPrefix(pkg, excludePackage+"/") {
continue PACKAGEINDEX
}
}
listCmd.Stdout = &pkgBuf
_ = listCmd.Run() // Ignore error
pkgBuf.Reset()
cmd := exec.Command("go", "list", "-find", "-f", `{{ .Doc }}`, pkg)
cmd.Dir = os.TempDir()
cmd.Stdout = &pkgBuf
setDeathSignal(cmd)
cmd.Run() // Ignore error
pkgLabel := pkg
if lastPkg != "" {
......@@ -232,8 +240,5 @@ func writeIndex(buf *bytes.Buffer, outDir string, basePath string, siteName stri
</html>
`)
err := ioutil.WriteFile(path.Join(outDir, "index.html"), buf.Bytes(), 0755)
if err != nil {
log.Fatalf("failed to write index: %s", err)
}
return ioutil.WriteFile(path.Join(outDir, "index.html"), buf.Bytes(), 0755)
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment