docs: stdlib index sorted alphabetically
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"unicode/utf8"
|
||||
@@ -365,6 +366,17 @@ func walkStdlib(ctx context.Context, output, format string) {
|
||||
return false
|
||||
}
|
||||
|
||||
// get filename from a package name
|
||||
getFileName := func(p string) string {
|
||||
filename := fmt.Sprintf("%s.%s", p, format)
|
||||
// If this package has sub-packages (e.g. `aws`), create
|
||||
// `aws/README.md` instead of `aws.md`.
|
||||
if hasSubPackages(p) {
|
||||
filename = fmt.Sprintf("%s/README.%s", p, format)
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
// Create main index
|
||||
index, err := os.Create(path.Join(output, "README.md"))
|
||||
if err != nil {
|
||||
@@ -372,14 +384,10 @@ func walkStdlib(ctx context.Context, output, format string) {
|
||||
}
|
||||
defer index.Close()
|
||||
fmt.Fprintf(index, "# Index\n\n")
|
||||
indexKeys := []string{}
|
||||
|
||||
for p, pkg := range packages {
|
||||
filename := fmt.Sprintf("%s.%s", p, format)
|
||||
// If this package has sub-packages (e.g. `aws`), create
|
||||
// `aws/README.md` instead of `aws.md`.
|
||||
if hasSubPackages(p) {
|
||||
filename = fmt.Sprintf("%s/README.%s", p, format)
|
||||
}
|
||||
filename := getFileName(p)
|
||||
filepath := path.Join(output, filename)
|
||||
|
||||
if err := os.MkdirAll(path.Dir(filepath), 0755); err != nil {
|
||||
@@ -392,8 +400,13 @@ func walkStdlib(ctx context.Context, output, format string) {
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// FIXME: sort packages by name
|
||||
fmt.Fprintf(index, "- [%s](./%s)\n", p, filename)
|
||||
indexKeys = append(indexKeys, p)
|
||||
fmt.Fprintf(f, "%s", pkg.Format(format))
|
||||
}
|
||||
|
||||
// Generate index from sorted list of packages
|
||||
sort.Strings(indexKeys)
|
||||
for _, p := range indexKeys {
|
||||
fmt.Fprintf(index, "- [%s](./%s)\n", p, getFileName(p))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user