Improved API documentation
This commit is contained in:
parent
c60c171a2f
commit
ea2e08d88d
@ -1,22 +1,37 @@
|
|||||||
package apiview
|
package apiview
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/animenotifier/arn/autodocs"
|
||||||
"github.com/animenotifier/notify.moe/components"
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get api page.
|
// Get api page.
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
types := []string{}
|
types := []*autodocs.Type{}
|
||||||
|
|
||||||
for typeName := range arn.DB.Types() {
|
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))
|
return ctx.HTML(components.API(types))
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
component API(types []string)
|
component API(types []*autodocs.Type)
|
||||||
.api-docs-page
|
.api-docs-page
|
||||||
h1 API
|
h1 API
|
||||||
|
|
||||||
@ -12,13 +12,10 @@ component API(types []string)
|
|||||||
span https://notify.moe/graphql
|
span https://notify.moe/graphql
|
||||||
|
|
||||||
h2 Types
|
h2 Types
|
||||||
table
|
table.api-types
|
||||||
//- thead
|
|
||||||
//- tr
|
|
||||||
//- th Table
|
|
||||||
tbody
|
tbody
|
||||||
each typeName in types
|
each typ in types
|
||||||
tr
|
tr
|
||||||
td= typeName
|
|
||||||
td
|
td
|
||||||
a(href="/api/" + strings.ToLower(typeName) + "/")= "/api/" + strings.ToLower(typeName) + "/"
|
a(href=typ.Endpoint())= typ.Name
|
||||||
|
td= typ.Comment
|
2
pages/apiview/api.scarlet
Normal file
2
pages/apiview/api.scarlet
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.api-types
|
||||||
|
max-width 100%
|
Loading…
Reference in New Issue
Block a user