mirror of
https://github.com/matrix-org/matrix-spec
synced 2025-12-28 03:48:36 +01:00
I was seeing duplicate endpoints appearing under each module (typically 2 of each). This turned out to be due to the `render-operation` partial being called multiple times (once when rendering the page, and another when rendering the left-hand-side TOC). We now check whether the endpoint has already been added to the list before insertion, via a "seen" map (for quick lookup).
43 lines
1.4 KiB
HTML
43 lines
1.4 KiB
HTML
{{/* 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>
|
|
{{/* Sort by module to group visually */}}
|
|
{{ $sorted := sort $endpoints "module" }}
|
|
{{ $current := "" }}
|
|
{{ range $sorted }}
|
|
{{ $mod := .module }}
|
|
{{/* Set a title for the base endpoints */}}
|
|
{{ if not $mod }}{{ $mod = "Required" }}{{ end }}
|
|
{{ if ne $mod $current }}
|
|
{{ if $current }}</ul></div>{{ end }}
|
|
<div class="endpoint-module">
|
|
<div class="endpoint-module-title">{{ $mod }}</div>
|
|
<ul class="endpoint-list">
|
|
{{ $current = $mod }}
|
|
{{ end }}
|
|
{{ $key := printf "%s|%s" .method .anchor }}
|
|
<li>
|
|
<a href="#{{ .anchor }}">
|
|
<span class="http-api-method">{{ .method }}</span>
|
|
<span class="endpoint-path">{{ .endpoint }}</span>
|
|
{{ if .deprecated }}<span class="endpoint-deprecated">(deprecated)</span>{{ end }}
|
|
</a>
|
|
</li>
|
|
{{ end }}
|
|
{{ if $current }}</ul></div>{{ end }}
|
|
</details>
|
|
</div>
|
|
{{ end }}
|