Skip to content

Commit 706d4f6

Browse files
committed
refactor(api): Simplify sidebar nav to sort by isConceptual, then alphabetically
- Remove api_nav_groups.yml config file (no longer needed) - Update api-menu-items.html to derive order from article data - Sort: conceptual tags (traitTags) first, then other tags alphabetically - Reduces template from 255 to 152 lines
1 parent 6eae4b7 commit 706d4f6

File tree

2 files changed

+73
-245
lines changed

2 files changed

+73
-245
lines changed

data/api_nav_groups.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

layouts/partials/sidebar/api-menu-items.html

Lines changed: 73 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
Generates <li class="nav-item"> elements matching Hugo's menu structure.
55
Used by nested-menu.html when rendering "InfluxDB HTTP API" menu item.
66

7+
Sort order: conceptual tags (traitTags) first, then other tags alphabetically.
8+
79
Parameters:
810
- page: Current page context
911
- url: URL of the API parent page (e.g., /influxdb3/core/api/)
1012

1113
Uses data from:
1214
- data/article_data/influxdb/{product}/articles.yml
13-
- data/api_nav_groups.yml
1415
*/}}
1516

1617
{{ $currentPage := .page }}
@@ -34,7 +35,6 @@
3435
{{/* Get article data for this product */}}
3536
{{ $siteData := .siteData }}
3637
{{ $articles := slice }}
37-
{{/* Data path: data/article_data/influxdb/{dataKey}/articles.yml -> siteData.article_data.influxdb.{dataKey}.articles.articles */}}
3838
{{ with $siteData.article_data }}
3939
{{ with index . "influxdb" }}
4040
{{ with index . $dataKey }}
@@ -47,9 +47,6 @@
4747
{{ end }}
4848
{{ end }}
4949

50-
{{/* Get navigation groups configuration */}}
51-
{{ $navGroups := $siteData.api_nav_groups.groups }}
52-
5350
{{/* Check if articles use tag-based structure */}}
5451
{{ $isTagBased := false }}
5552
{{ if gt (len $articles) 0 }}
@@ -65,190 +62,90 @@
6562
{{ end }}
6663
{{ end }}
6764

68-
{{ if and (gt (len $articles) 0) $navGroups $isTagBased }}
69-
{{/* Build a map of tag slug -> article for quick lookup */}}
70-
{{ $articlesByTag := dict }}
65+
{{ if and (gt (len $articles) 0) $isTagBased }}
66+
{{/* Separate conceptual (traitTag) and non-conceptual articles */}}
67+
{{ $conceptualArticles := slice }}
68+
{{ $operationArticles := slice }}
69+
7170
{{ range $articles }}
7271
{{ if and (reflect.IsMap .) (isset . "fields") }}
7372
{{ $fields := index . "fields" }}
74-
{{ if and (reflect.IsMap $fields) (isset $fields "tag") }}
75-
{{ $tag := index $fields "tag" }}
76-
{{ $articlesByTag = merge $articlesByTag (dict $tag .) }}
73+
{{ if reflect.IsMap $fields }}
74+
{{ $isConceptual := false }}
75+
{{ if isset $fields "isConceptual" }}
76+
{{ $isConceptual = index $fields "isConceptual" }}
77+
{{ end }}
78+
{{ if $isConceptual }}
79+
{{ $conceptualArticles = $conceptualArticles | append . }}
80+
{{ else }}
81+
{{ $operationArticles = $operationArticles | append . }}
82+
{{ end }}
7783
{{ end }}
7884
{{ end }}
7985
{{ end }}
8086

81-
{{/* Render navigation groups */}}
82-
{{ range $groupIdx, $group := $navGroups }}
83-
{{ $groupTags := $group.tags }}
84-
{{ $groupHasArticles := false }}
85-
86-
{{/* Check if any tags in this group have articles */}}
87-
{{ range $groupTags }}
88-
{{ if index $articlesByTag . }}
89-
{{ $groupHasArticles = true }}
90-
{{ end }}
87+
{{/* Sort each group alphabetically by tag name */}}
88+
{{ $conceptualArticles = sort $conceptualArticles "fields.tag" }}
89+
{{ $operationArticles = sort $operationArticles "fields.tag" }}
90+
91+
{{/* Combine: conceptual first, then operations */}}
92+
{{ $sortedArticles := $conceptualArticles | append $operationArticles }}
93+
94+
{{/* Render each tag as a nav item */}}
95+
{{ range $sortedArticles }}
96+
{{ $path := index . "path" }}
97+
{{ $fields := index . "fields" }}
98+
{{ $tag := index $fields "tag" }}
99+
{{ $tagPageUrl := print "/" $product "/" $version "/" $path "/" | relURL }}
100+
{{ $isActive := eq $currentPage.RelPermalink (print "/" $product "/" $version "/" $path "/") }}
101+
102+
{{/* Get operations */}}
103+
{{ $operations := slice }}
104+
{{ if isset $fields "operations" }}
105+
{{ $operations = index $fields "operations" }}
91106
{{ end }}
92107

93-
{{ if $groupHasArticles }}
94-
{{/* Count actual articles in this group */}}
95-
{{ $articlesInGroup := slice }}
96-
{{ range $groupTags }}
97-
{{ $article := index $articlesByTag . }}
98-
{{ if $article }}
99-
{{ $articlesInGroup = $articlesInGroup | append $article }}
100-
{{ end }}
101-
{{ end }}
102-
{{ $isSingleTag := eq (len $articlesInGroup) 1 }}
103-
104-
{{/* Check if this group should be open (contains active page or active operation) */}}
105-
{{ $groupIsOpen := false }}
106-
{{ range $articlesInGroup }}
107-
{{ $path := index . "path" }}
108-
{{ $pageUrl := print "/" $product "/" $version "/" $path "/" }}
109-
{{ if eq $currentPage.RelPermalink $pageUrl }}
110-
{{ $groupIsOpen = true }}
111-
{{ end }}
112-
{{/* Also check if any operation pages in this group are active */}}
113-
{{ $fields := index . "fields" }}
114-
{{ if and (reflect.IsMap $fields) (isset $fields "operations") }}
115-
{{ range index $fields "operations" }}
116-
{{ $opPathSlug := .path | replaceRE "^/" "" }}
117-
{{ $opUrl := printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method) }}
118-
{{ if eq $currentPage.RelPermalink $opUrl }}
119-
{{ $groupIsOpen = true }}
120-
{{ end }}
121-
{{ end }}
122-
{{ end }}
108+
{{/* Don't show operations for conceptual/traitTag pages */}}
109+
{{ $isConceptual := false }}
110+
{{ if isset $fields "isConceptual" }}
111+
{{ $isConceptual = index $fields "isConceptual" }}
112+
{{ end }}
113+
{{ $hasOperations := and (gt (len $operations) 0) (not $isConceptual) }}
114+
115+
{{/* Check if any operation in this tag is active */}}
116+
{{ $tagHasActiveOp := false }}
117+
{{ range $operations }}
118+
{{ $opPathSlug := .path | replaceRE "^/" "" }}
119+
{{ $opUrl := printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method) }}
120+
{{ if eq $currentPage.RelPermalink $opUrl }}
121+
{{ $tagHasActiveOp = true }}
123122
{{ end }}
123+
{{ end }}
124124

125-
{{ if $isSingleTag }}
126-
{{/* Single tag group: direct link to tag page with operations as children */}}
127-
{{ $article := index $articlesInGroup 0 }}
128-
{{ $path := index $article "path" }}
129-
{{ $fields := index $article "fields" }}
130-
{{ $tagPageUrl := print "/" $product "/" $version "/" $path "/" | relURL }}
131-
{{ $isActive := eq $currentPage.RelPermalink (print "/" $product "/" $version "/" $path "/") }}
132-
{{ $operations := slice }}
133-
{{ if and (reflect.IsMap $fields) (isset $fields "operations") }}
134-
{{ $operations = index $fields "operations" }}
135-
{{ end }}
136-
{{/* Don't show operations for conceptual/traitTag pages (e.g., Authentication) */}}
137-
{{ $isConceptual := false }}
138-
{{ if and (reflect.IsMap $fields) (isset $fields "isConceptual") }}
139-
{{ $isConceptual = index $fields "isConceptual" }}
140-
{{ end }}
141-
{{ $hasOperations := and (gt (len $operations) 0) (not $isConceptual) }}
142-
143-
<li class="nav-item{{ if $isActive }} active{{ end }}">
144-
{{ if $hasOperations }}<a href="#" class="children-toggle{{ if or $isActive $groupIsOpen }} open{{ end }}"></a>{{ end }}
145-
<a href="{{ $tagPageUrl }}">{{ $group.name }}</a>
146-
{{ if $hasOperations }}
147-
<ul class="children{{ if or $isActive $groupIsOpen }} open{{ end }}">
148-
{{ range $operations }}
149-
{{ $apiPath := .path }}
150-
{{/* Build path-based URL for standalone operation page */}}
151-
{{ $opPathSlug := $apiPath | replaceRE "^/" "" }}
152-
{{ $operationUrl := printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method) | relURL }}
153-
{{/* Check if this operation page is active */}}
154-
{{ $opIsActive := eq $currentPage.RelPermalink (printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method)) }}
155-
<li class="nav-item api-operation{{ if $opIsActive }} active{{ end }}">
156-
<a href="{{ $operationUrl | safeURL }}">
157-
<span class="api-method api-method--{{ lower .method }}">{{ upper .method }}</span>
158-
{{- $summary := .summary -}}
159-
{{- with .compatVersion -}}
160-
{{- /* Strip redundant compatibility text when badge is shown */ -}}
161-
{{- $summary = replaceRE `\s*\(v[12]-compatible\)` "" $summary -}}
162-
{{- end -}}
163-
{{ with $summary }}{{ . }}{{ else }}<code>{{ $apiPath }}</code>{{ end }}
164-
{{ with .compatVersion }}<span class="api-compat-badge api-compat-badge--{{ . }}" title="InfluxDB {{ . }}-compatible endpoint">{{ . }}</span>{{ end }}
165-
</a>
166-
</li>
167-
{{ end }}
168-
</ul>
169-
{{ end }}
125+
<li class="nav-item{{ if $isActive }} active{{ end }}">
126+
{{ if $hasOperations }}<a href="#" class="children-toggle{{ if or $isActive $tagHasActiveOp }} open{{ end }}"></a>{{ end }}
127+
<a href="{{ $tagPageUrl }}">{{ $tag }}</a>
128+
{{ if $hasOperations }}
129+
<ul class="children{{ if or $isActive $tagHasActiveOp }} open{{ end }}">
130+
{{ range $operations }}
131+
{{ $apiPath := .path }}
132+
{{ $opPathSlug := $apiPath | replaceRE "^/" "" }}
133+
{{ $operationUrl := printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method) | relURL }}
134+
{{ $opIsActive := eq $currentPage.RelPermalink (printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method)) }}
135+
<li class="nav-item api-operation{{ if $opIsActive }} active{{ end }}">
136+
<a href="{{ $operationUrl | safeURL }}">
137+
<span class="api-method api-method--{{ lower .method }}">{{ upper .method }}</span>
138+
{{- $summary := .summary -}}
139+
{{- with .compatVersion -}}
140+
{{- $summary = replaceRE `\s*\(v[12]-compatible\)` "" $summary -}}
141+
{{- end -}}
142+
{{ with $summary }}{{ . }}{{ else }}<code>{{ $apiPath }}</code>{{ end }}
143+
{{ with .compatVersion }}<span class="api-compat-badge api-compat-badge--{{ . }}" title="InfluxDB {{ . }}-compatible endpoint">{{ . }}</span>{{ end }}
144+
</a>
170145
</li>
171-
172-
{{ else }}
173-
{{/* Multi-tag group: group label (or link if url defined) with tag pages as children */}}
174-
{{ $groupUrl := "" }}
175-
{{ $groupIsActive := false }}
176-
{{ with $group.url }}
177-
{{ $groupUrl = print "/" $product "/" $version "/api/" . "/" | relURL }}
178-
{{ $groupIsActive = eq $currentPage.RelPermalink (print "/" $product "/" $version "/api/" . "/") }}
179146
{{ end }}
180-
<li class="nav-item{{ if $groupIsActive }} active{{ end }}">
181-
<a href="#" class="children-toggle{{ if or $groupIsOpen $groupIsActive }} open{{ end }}"></a>
182-
{{ if $groupUrl }}
183-
<a href="{{ $groupUrl }}">{{ $group.name }}</a>
184-
{{ else }}
185-
<span class="nav-group-label">{{ $group.name }}</span>
186-
{{ end }}
187-
<ul class="children{{ if or $groupIsOpen $groupIsActive }} open{{ end }}">
188-
{{ range $tagIdx, $tagName := $groupTags }}
189-
{{ $article := index $articlesByTag $tagName }}
190-
{{ if $article }}
191-
{{ $path := index $article "path" }}
192-
{{ $fields := index $article "fields" }}
193-
{{ $tagPageUrl := print "/" $product "/" $version "/" $path "/" | relURL }}
194-
{{ $isActive := eq $currentPage.RelPermalink (print "/" $product "/" $version "/" $path "/") }}
195-
{{ $operations := slice }}
196-
{{ if and (reflect.IsMap $fields) (isset $fields "operations") }}
197-
{{ $operations = index $fields "operations" }}
198-
{{ end }}
199-
{{ $menuName := $tagName }}
200-
{{ if and (reflect.IsMap $fields) (isset $fields "menuName") }}
201-
{{ $menuName = index $fields "menuName" }}
202-
{{ end }}
203-
{{/* Don't show operations for conceptual/traitTag pages (e.g., Authentication) */}}
204-
{{ $isConceptual := false }}
205-
{{ if and (reflect.IsMap $fields) (isset $fields "isConceptual") }}
206-
{{ $isConceptual = index $fields "isConceptual" }}
207-
{{ end }}
208-
{{ $hasOperations := and (gt (len $operations) 0) (not $isConceptual) }}
209-
210-
<li class="nav-item{{ if $isActive }} active{{ end }}">
211-
{{ if $hasOperations }}<a href="#" class="children-toggle{{ if $isActive }} open{{ end }}"></a>{{ end }}
212-
<a href="{{ $tagPageUrl }}">{{ $menuName }}</a>
213-
{{/* Check if any operation in this tag is active */}}
214-
{{ $tagHasActiveOp := false }}
215-
{{ range $operations }}
216-
{{ $opPathSlug := .path | replaceRE "^/" "" }}
217-
{{ $opUrl := printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method) }}
218-
{{ if eq $currentPage.RelPermalink $opUrl }}
219-
{{ $tagHasActiveOp = true }}
220-
{{ end }}
221-
{{ end }}
222-
{{ if $hasOperations }}
223-
<ul class="children{{ if or $isActive $tagHasActiveOp }} open{{ end }}">
224-
{{ range $operations }}
225-
{{ $apiPath := .path }}
226-
{{/* Build path-based URL for standalone operation page */}}
227-
{{ $opPathSlug := $apiPath | replaceRE "^/" "" }}
228-
{{ $operationUrl := printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method) | relURL }}
229-
{{/* Check if this operation page is active */}}
230-
{{ $opIsActive := eq $currentPage.RelPermalink (printf "/%s/%s/api/%s/%s/" $product $version $opPathSlug (lower .method)) }}
231-
<li class="nav-item api-operation{{ if $opIsActive }} active{{ end }}">
232-
<a href="{{ $operationUrl | safeURL }}">
233-
<span class="api-method api-method--{{ lower .method }}">{{ upper .method }}</span>
234-
{{- $summary := .summary -}}
235-
{{- with .compatVersion -}}
236-
{{- /* Strip redundant compatibility text when badge is shown */ -}}
237-
{{- $summary = replaceRE `\s*\(v[12]-compatible\)` "" $summary -}}
238-
{{- end -}}
239-
{{ with $summary }}{{ . }}{{ else }}<code>{{ $apiPath }}</code>{{ end }}
240-
{{ with .compatVersion }}<span class="api-compat-badge api-compat-badge--{{ . }}" title="InfluxDB {{ . }}-compatible endpoint">{{ . }}</span>{{ end }}
241-
</a>
242-
</li>
243-
{{ end }}
244-
</ul>
245-
{{ end }}
246-
</li>
247-
{{ end }}
248-
{{ end }}
249-
</ul>
250-
</li>
147+
</ul>
251148
{{ end }}
252-
{{ end }}
149+
</li>
253150
{{ end }}
254151
{{ end }}

0 commit comments

Comments
 (0)