From ea2e08d88db243fefae2c7dcfc853b1e9cf2f0ec Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 12 Apr 2018 23:05:24 +0200 Subject: [PATCH] Improved API documentation --- pages/apiview/api.go | 21 ++++++++++++++++++--- pages/apiview/api.pixy | 13 +++++-------- pages/apiview/api.scarlet | 2 ++ 3 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 pages/apiview/api.scarlet diff --git a/pages/apiview/api.go b/pages/apiview/api.go index 31213c6e..8caa2e1e 100644 --- a/pages/apiview/api.go +++ b/pages/apiview/api.go @@ -1,22 +1,37 @@ package apiview import ( + "path" "sort" "github.com/aerogo/aero" "github.com/animenotifier/arn" + "github.com/animenotifier/arn/autodocs" "github.com/animenotifier/notify.moe/components" + "github.com/fatih/color" ) // Get api page. func Get(ctx *aero.Context) string { - types := []string{} + types := []*autodocs.Type{} for typeName := range arn.DB.Types() { - types = append(types, typeName) + if typeName == "Session" { + continue + } + + typ, err := autodocs.GetTypeDocumentation(typeName, path.Join(arn.Root, "..", "arn", typeName+".go")) + types = append(types, typ) + + if err != nil { + color.Red(err.Error()) + continue + } } - sort.Strings(types) + sort.Slice(types, func(i, j int) bool { + return types[i].Name < types[j].Name + }) return ctx.HTML(components.API(types)) } diff --git a/pages/apiview/api.pixy b/pages/apiview/api.pixy index 50bcf447..dc920864 100644 --- a/pages/apiview/api.pixy +++ b/pages/apiview/api.pixy @@ -1,4 +1,4 @@ -component API(types []string) +component API(types []*autodocs.Type) .api-docs-page h1 API @@ -12,13 +12,10 @@ component API(types []string) span https://notify.moe/graphql h2 Types - table - //- thead - //- tr - //- th Table + table.api-types tbody - each typeName in types + each typ in types tr - td= typeName td - a(href="/api/" + strings.ToLower(typeName) + "/")= "/api/" + strings.ToLower(typeName) + "/" \ No newline at end of file + a(href=typ.Endpoint())= typ.Name + td= typ.Comment \ No newline at end of file diff --git a/pages/apiview/api.scarlet b/pages/apiview/api.scarlet new file mode 100644 index 00000000..5a358616 --- /dev/null +++ b/pages/apiview/api.scarlet @@ -0,0 +1,2 @@ +.api-types + max-width 100% \ No newline at end of file