diff --git a/README.md b/README.md index d6617a7..eb4e7b2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +![](https://github.com/elastic/crd-ref-docs/workflows/Build/badge.svg) + + CRD Reference Documentation Generator ====================================== diff --git a/templates/asciidoctor/type.tpl b/templates/asciidoctor/type.tpl index ed95d17..24592b5 100644 --- a/templates/asciidoctor/type.tpl +++ b/templates/asciidoctor/type.tpl @@ -10,7 +10,7 @@ {{ if $type.References -}} .Appears In: **** -{{- range $type.References }} +{{- range $type.SortedReferences }} - {{ asciidocRenderTypeLink . }} {{- end }} **** diff --git a/types/types.go b/types/types.go index 5dbbb77..ef335f5 100644 --- a/types/types.go +++ b/types/types.go @@ -174,6 +174,26 @@ func (t *Type) IsAlias() bool { return t.Kind == AliasKind } +func (t *Type) SortedReferences() []*Type { + if t == nil || len(t.References) == 0 { + return nil + } + + sort.Slice(t.References, func(i, j int) bool { + if t.References[i].Name < t.References[j].Name { + return true + } + + if t.References[i].Name == t.References[j].Name { + return t.References[i].Package < t.References[j].Package + } + + return false + }) + + return t.References +} + // Field describes a field in a struct. type Field struct { Name string