Add an endpoints table of contents

A simple list of endpoints that one can ctrl-f through.
This commit is contained in:
Andrew Morgan 2025-12-05 15:12:15 +00:00
parent 82a67a1fab
commit 56d48eb3a8
3 changed files with 70 additions and 2 deletions

View file

@ -257,6 +257,45 @@ Custom SCSS for the Matrix spec
}
.endpoints-toc {
summary {
cursor: pointer;
font-weight: $font-weight-bold;
font-size: 1.05rem;
margin-bottom: 0.5rem;
}
.endpoint-list {
list-style: none;
padding-left: 0;
margin: 0;
}
.endpoint-list li {
margin: 0.2rem 0;
}
.endpoint-list a {
text-decoration: none;
color: inherit;
}
.endpoint-list .http-api-method {
font-weight: $font-weight-bold;
margin-right: 0.35rem;
}
.endpoint-path {
font-family: $font-family-monospace;
color: $secondary;
}
}
.page-description {
margin-bottom: 1rem;
color: inherit;
}
/* Styles for alert boxes */
.alert {
&.note {
@ -581,4 +620,4 @@ dd {
.breadcrumb {
margin: 0;
}
}
}

View file

@ -0,0 +1,28 @@
{{/* Minimal list of API endpoints for the current page. */}}
{{ $raw := .Scratch.Get "api_endpoints" }}
{{/* Normalize to a slice */}}
{{ $endpoints := slice }}
{{ if reflect.IsSlice $raw }}
{{ $endpoints = $raw }}
{{ else if reflect.IsMap $raw }}
{{ range $raw }}
{{ $endpoints = append $endpoints . }}
{{ end }}
{{ end }}
{{ if gt (len $endpoints) 0 }}
<div class="endpoints-toc mb-4">
<details>
<summary>List of Endpoints</summary>
<ul class="endpoint-list">
{{ range $endpoints }}
<li>
<a href="#{{ .anchor }}">
<span class="http-api-method">{{ .method }}</span>
<span class="endpoint-path">{{ .endpoint }}</span>
</a>
</li>
{{ end }}
</ul>
</details>
</div>
{{ end }}

View file

@ -7,7 +7,8 @@
{{ define "main" }}
<div class="td-content">
<h1>{{ .Title }}</h1>
{{ with .Params.description }}<div class="lead">{{ . | markdownify }}</div>{{ end }}
{{ with .Params.description }}<p class="page-description">{{ . | markdownify }}</p>{{ end }}
{{ partial "endpoints-toc.html" . }}
{{ .Content }}
</div>
{{ end }}