mirror of
https://github.com/matrix-org/matrix-spec
synced 2025-12-27 11:28:38 +01:00
Fix duplicate modules endpoints
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).
This commit is contained in:
parent
468fcb3992
commit
f30e850bf1
|
|
@ -16,9 +16,9 @@
|
|||
{{/* Sort by module to group visually */}}
|
||||
{{ $sorted := sort $endpoints "module" }}
|
||||
{{ $current := "" }}
|
||||
{{ $seen := newScratch }}
|
||||
{{ 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 }}
|
||||
|
|
@ -28,16 +28,13 @@
|
|||
{{ $current = $mod }}
|
||||
{{ end }}
|
||||
{{ $key := printf "%s|%s" .method .anchor }}
|
||||
{{ if not ($seen.Get $key) }}
|
||||
{{ $seen.Set $key true }}
|
||||
<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 }}
|
||||
<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>
|
||||
|
|
|
|||
|
|
@ -35,10 +35,21 @@
|
|||
{{ if $page }}
|
||||
{{/* Store each endpoint's metadata in a scratch variable */}}
|
||||
{{ $entry := dict "anchor" $anchor "method" $method "endpoint" $endpoint "summary" $operation_data.summary "deprecated" $operation_data.deprecated "module" $module }}
|
||||
{{ if not ($page.Scratch.Get "api_endpoints_seen") }}
|
||||
{{ $page.Scratch.Set "api_endpoints_seen" dict }}
|
||||
{{ end }}
|
||||
{{/* Keep a map of seen endpoints. This is necessary as this partial may be
|
||||
rendered multiple times for the same endpoint (e.g. in the TOC and
|
||||
in the main content), leading to duplicates. */}}
|
||||
{{ $seen := $page.Scratch.Get "api_endpoints_seen" }}
|
||||
{{ $key := printf "%s|%s" $method $endpoint }}
|
||||
{{ if not (index $seen $key) }}
|
||||
{{ if not (reflect.IsSlice ($page.Scratch.Get "api_endpoints")) }}
|
||||
{{ $page.Scratch.Set "api_endpoints" (slice) }}
|
||||
{{ end }}
|
||||
{{ $page.Scratch.Add "api_endpoints" (slice $entry) }}
|
||||
{{ $page.Scratch.SetInMap "api_endpoints_seen" $key true }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
<section class="rendered-data">
|
||||
|
|
|
|||
Loading…
Reference in a new issue