docs: stdlib index sorted alphabetically

Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
Sam Alba 2021-06-23 10:49:19 +02:00
parent b5550d0766
commit b03e695970
2 changed files with 41 additions and 28 deletions

View File

@ -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))
}
}

View File

@ -1,28 +1,28 @@
# Index
- [aws](./aws/README.md)
- [aws/ecr](./aws/ecr.md)
- [aws/rds](./aws/rds.md)
- [git](./git.md)
- [kubernetes](./kubernetes/README.md)
- [terraform](./terraform.md)
- [random](./random.md)
- [aws/ecs](./aws/ecs.md)
- [aws/s3](./aws/s3.md)
- [dagger/op](./dagger/op.md)
- [gcp](./gcp/README.md)
- [go](./go.md)
- [js/yarn](./js/yarn.md)
- [kubernetes/helm](./kubernetes/helm.md)
- [docker](./docker.md)
- [gcp/gcr](./gcp/gcr.md)
- [gcp/gke](./gcp/gke.md)
- [io](./io.md)
- [kubernetes/kustomize](./kubernetes/kustomize.md)
- [os](./os.md)
- [alpine](./alpine.md)
- [aws](./aws/README.md)
- [aws/cloudformation](./aws/cloudformation.md)
- [aws/ecr](./aws/ecr.md)
- [aws/ecs](./aws/ecs.md)
- [aws/eks](./aws/eks.md)
- [aws/elb](./aws/elb.md)
- [aws/rds](./aws/rds.md)
- [aws/s3](./aws/s3.md)
- [dagger](./dagger/README.md)
- [dagger/op](./dagger/op.md)
- [docker](./docker.md)
- [gcp](./gcp/README.md)
- [gcp/gcr](./gcp/gcr.md)
- [gcp/gke](./gcp/gke.md)
- [git](./git.md)
- [go](./go.md)
- [io](./io.md)
- [js/yarn](./js/yarn.md)
- [kubernetes](./kubernetes/README.md)
- [kubernetes/helm](./kubernetes/helm.md)
- [kubernetes/kustomize](./kubernetes/kustomize.md)
- [netlify](./netlify.md)
- [os](./os.md)
- [random](./random.md)
- [terraform](./terraform.md)