1
0
Fork 0
mirror of https://git.sr.ht/~ashkeel/strimertul-website synced 2024-11-23 21:32:20 +00:00

versioned api ref

This commit is contained in:
Ash Keel 2023-03-06 17:01:31 +01:00
parent 65e79d1126
commit c02607bee1
No known key found for this signature in database
GPG key ID: BAD8D93E7314ED3E
6 changed files with 145 additions and 85 deletions

9
content/api/v31.md Normal file
View file

@ -0,0 +1,9 @@
---
menu: apiversions
title: v3.1.x
version: v31
aliases:
- latest
- api/
---

View file

@ -1,99 +1,17 @@
{{ define "schema" }}
{{ with .description }}<blockquote>{{ . }}</blockquote>{{ end }}
<code>
{{ with .element }}
{{ with $.name }}
<div class="nameblock"><span class="name">{{ . }}</span>:</div>
{{ end }}
{{ if (eq $.kind "array") }}
<span class="kind {{ $.kind }}">arrayOf</span> [
{{ template "schema" . }}
]
{{ end }}
{{ if (eq $.kind "dictionary") }}
<span class="kind {{ $.kind }}">dictionary</span>
<div class="dict">
<
<span class="key">
<span class="kind {{ $.key.kind }}">{{ $.key.name }}</span></span
>, <span class="element">{{ template "schema" . }}</span>>
</div>
{{ end }}
{{ else }}
{{ if (eq .name .kind) }}
<span class="kind {{ $.kind }}">{{ .kind }}</span>
{{ else }}
{{ with .name }}
<div class="nameblock">
<span class="name">{{ . }}</span>{{ if $.isPointer }}
<abbr class="pointer" title="Optional, might not be in the object"
>*</abbr
>
{{ end }}:
</div>
{{ end }}
{{ if (eq $.kind "enum") }}
<span class="kind {{ $.kind }}">enum</span> (
{{ with $.enumValues }}{{ delimit . " | " }}{{ end }}
)
{{ else }}
<span class="kind {{ $.kind }}">{{ .kind }}</span>
{{ end }}
{{ end }}
{{ with .keys }}
{
{{ range . }}
<ul>
<li>{{ template "schema" . }}</li>
</ul>
{{ end }}
}
{{ end }}
{{ end }}
</code>
{{ end }}
{{ define "main" }}
{{ $keys := .Site.Data.api.v310.api }}
<main class="apidocs">
<nav>
<header>Kilovolt keys</header>
<header>strimertül version</header>
<ul>
{{ range $key, $spec := $keys }}
{{ range .Pages.Reverse }}
<li>
<a href="#{{ anchorize $key | safeURL }}" class="monotitle"
>{{ $key }}</a
>
<a href="{{ .RelPermalink }}" class="monotitle">{{ .Title }}</a>
</li>
{{ end }}
</ul>
</nav>
<div class="doc">
<section class="copy">{{ .Content }}</section>
<section class="reference">
{{ range $key, $spec := $keys }}
<article class="api" id="{{ anchorize $key | safeURL }}">
<header>
<h3>
<a href="#{{ anchorize $key | safeURL }}" class="heading-anchor"
>#</a
>
<span class="monotitle">{{ $key }}</span> {{ range .tags }}
<span class="tag {{ . }}">{{ . }}</span>
{{ end }}
</h3>
{{ with .description }}
<div class="description">{{ . }}</div>
{{ end }}
{{ with .schema }}
<div class="schema">
{{ template "schema" . }}
</div>
{{ end }}
</header>
</article>
{{ end }}
</section>
</div>
</main>
{{ end }}

116
layouts/api/single.html Normal file
View file

@ -0,0 +1,116 @@
{{ define "schema" }}
{{ with .description }}<blockquote>{{ . }}</blockquote>{{ end }}
<code>
{{ with .element }}
{{ with $.name }}
<div class="nameblock"><span class="name">{{ . }}</span>:</div>
{{ end }}
{{ if (eq $.kind "array") }}
<span class="kind {{ $.kind }}">arrayOf</span> [
{{ template "schema" . }}
]
{{ end }}
{{ if (eq $.kind "dictionary") }}
<span class="kind {{ $.kind }}">dictionary</span>
<div class="dict">
<
<span class="key">
<span class="kind {{ $.key.kind }}">{{ $.key.name }}</span></span
>, <span class="element">{{ template "schema" . }}</span>>
</div>
{{ end }}
{{ else }}
{{ if (eq .name .kind) }}
<span class="kind {{ $.kind }}">{{ .kind }}</span>
{{ else }}
{{ with .name }}
<div class="nameblock">
<span class="name">{{ . }}</span>{{ if $.isPointer }}
<abbr class="pointer" title="Optional, might not be in the object"
>*</abbr
>
{{ end }}:
</div>
{{ end }}
{{ if (eq $.kind "enum") }}
<span class="kind {{ $.kind }}">enum</span> (
{{ with $.enumValues }}{{ delimit . " | " }}{{ end }}
)
{{ else }}
<span class="kind {{ $.kind }}">{{ .kind }}</span>
{{ end }}
{{ end }}
{{ with .keys }}
{
{{ range . }}
<ul>
<li>{{ template "schema" . }}</li>
</ul>
{{ end }}
}
{{ end }}
{{ end }}
</code>
{{ end }}
{{ define "main" }}
{{ $datafile := index .Site.Data.api .Params.version }}
{{ $keys := $datafile.api }}
<main class="apidocs">
<nav>
<header>API version</header>
<select id="api-version">
{{ $currentPage := . }}
{{ range $.Site.Menus.apiversions }}
<option
value="{{ .URL }}"
{{ if $currentPage.IsMenuCurrent "apiversions" . }}selected{{ end }}
>
{{ .Title }}
</option>
{{ end }}
</select>
<header>Kilovolt keys</header>
<ul>
{{ range $key, $spec := $keys }}
<li>
<a href="#{{ anchorize $key | safeURL }}" class="monotitle"
>{{ $key }}</a
>
</li>
{{ end }}
</ul>
</nav>
<div class="doc">
<section class="copy">
<header><h1>strimertül {{ .Title }} API</h1></header>
{{ .Content }}
</section>
<section class="reference">
{{ range $key, $spec := $keys }}
<article class="api" id="{{ anchorize $key | safeURL }}">
<header>
<h3>
<a href="#{{ anchorize $key | safeURL }}" class="heading-anchor"
>#</a
>
<span class="monotitle">{{ $key }}</span> {{ range .tags }}
<span class="tag {{ . }}">{{ . }}</span>
{{ end }}
</h3>
{{ with .description }}
<div class="description">{{ . }}</div>
{{ end }}
{{ with .schema }}
<div class="schema">
{{ template "schema" . }}
</div>
{{ end }}
</header>
</article>
{{ end }}
</section>
</div>
</main>
<script async defer src="/script/apiselector.js"></script>
{{ end }}

View file

@ -0,0 +1,4 @@
const apiselect = document.getElementById("api-version");
apiselect.addEventListener("change", (ev) => {
location.href = ev.target.value;
});

View file

@ -21,6 +21,8 @@
padding: 1rem;
}
& > nav {
display: flex;
flex-direction: column;
background-color: $gray2;
padding: 0;
grid-column: 1;
@ -97,6 +99,17 @@
}
}
select {
background-color: $gray2;
color: $gray12;
border-radius: 4px;
}
#api-version {
margin: 1rem;
margin-bottom: 0;
}
.schema {
margin-top: 1rem;
code > ul:first-of-type > li > blockquote {