fix(api): use reliable path extraction for dual download buttons
Replace unreliable findRE regex with split-based path extraction for version detection in API section index pages. The previous regex "[^/]+.*?" was inconsistent and could fail to extract version correctly. Changes: - layouts/_default/api.html: Add dual-button logic for clustered/cloud-dedicated section index pages using split-based URL path extraction - layouts/api/list.html: Replace findRE with split for version extraction - layouts/api/section.html: Add dual-button logic matching api.html The split approach extracts path segments reliably: /influxdb3/clustered/api/ → ["", "influxdb3", "clustered", "api", ""] $version = index 2 = "clustered"claude/api-code-samples-plan-MEkQO
parent
89c62812f6
commit
345bdc3058
|
|
@ -3,7 +3,17 @@ pages. Delegates to appropriate templates based on page type: - Section pages:
|
|||
Use section.html logic (children listing) - Pages with staticFilePath: Use
|
||||
RapiDoc renderer Note: This template exists as a catch-all but specific
|
||||
templates (api/section.html, api/list.html, api/single.html) should be
|
||||
preferred. */}} {{/* Section pages without staticFilePath should render content
|
||||
preferred. */}}
|
||||
|
||||
{{/* Extract product and version from URL path for download buttons */}}
|
||||
{{/* Example: /influxdb3/clustered/api/ → ["", "influxdb3", "clustered", "api", ""] */}}
|
||||
{{ $pathParts := split .RelPermalink "/" }}
|
||||
{{ $version := "" }}
|
||||
{{ if ge (len $pathParts) 3 }}
|
||||
{{ $version = index $pathParts 2 }}
|
||||
{{ end }}
|
||||
|
||||
{{/* Section pages without staticFilePath should render content
|
||||
directly, not use RapiDoc */}} {{ if and .IsSection (not .Params.staticFilePath)
|
||||
}} {{ partial "header.html" . }} {{ partial "topnav.html" . }}
|
||||
|
||||
|
|
@ -20,6 +30,26 @@ directly, not use RapiDoc */}} {{ if and .IsSection (not .Params.staticFilePath)
|
|||
{{ end }}
|
||||
</header>
|
||||
|
||||
{{/* Dual download buttons for Clustered and Cloud Dedicated */}}
|
||||
{{ if or (eq $version "clustered") (eq $version "cloud-dedicated") }}
|
||||
<div class="api-spec-actions api-spec-actions--dual">
|
||||
<a href="/openapi/influxdb-{{ $version }}-v2-data-api.yml" class="btn api-spec-download" download>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
||||
<path d="M8 12L3 7h3V2h4v5h3L8 12z"/>
|
||||
<path d="M1 14h14v2H1v-2z"/>
|
||||
</svg>
|
||||
Download Data API Spec
|
||||
</a>
|
||||
<a href="/openapi/influxdb-{{ $version }}-management-api.yml" class="btn api-spec-download" download>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
||||
<path d="M8 12L3 7h3V2h4v5h3L8 12z"/>
|
||||
<path d="M1 14h14v2H1v-2z"/>
|
||||
</svg>
|
||||
Download Management API Spec
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{/* SECTION INDEX - Show page content then children listing */}} {{
|
||||
with .Content }}
|
||||
<section class="api-section-content">{{ . }}</section>
|
||||
|
|
@ -58,3 +88,25 @@ partial "topnav.html" . }}
|
|||
</div>
|
||||
|
||||
{{ partial "footer.html" . }} {{ end }}
|
||||
|
||||
<style>
|
||||
/* Dual download buttons container for Clustered/Cloud Dedicated */
|
||||
.api-spec-actions--dual {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
/* Responsive - stack buttons on smaller screens */
|
||||
@media (max-width: 600px) {
|
||||
.api-spec-actions--dual {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.api-spec-actions--dual .api-spec-download {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -3,10 +3,15 @@ param) - shows list of tag pages from article data 2. Tag pages (has 'tag'
|
|||
param) - shows RapiDoc with all operations for the tag For conceptual pages
|
||||
(isConceptual: true), shows content without operations. */}}
|
||||
|
||||
{{/* Extract product and version from URL for download buttons */}}
|
||||
{{ $productPathData := findRE "[^/]+.*?" .RelPermalink }}
|
||||
{{ $product := index $productPathData 0 }}
|
||||
{{ $version := index $productPathData 1 }}
|
||||
{{/* Extract product and version from URL path for download buttons */}}
|
||||
{{/* Example: /influxdb3/clustered/api/ → ["", "influxdb3", "clustered", "api", ""] */}}
|
||||
{{ $pathParts := split .RelPermalink "/" }}
|
||||
{{ $product := "" }}
|
||||
{{ $version := "" }}
|
||||
{{ if ge (len $pathParts) 3 }}
|
||||
{{ $product = index $pathParts 1 }}
|
||||
{{ $version = index $pathParts 2 }}
|
||||
{{ end }}
|
||||
|
||||
<!-- USING_API_LIST_HTML_TEMPLATE -->
|
||||
{{ partial "header.html" . }} {{ partial "topnav.html" . }}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,17 @@
|
|||
{{/* API Documentation Section Layout Used for API section index pages (e.g.,
|
||||
/influxdb3/core/api/). Shows page content with children listing instead of
|
||||
RapiDoc renderer. For tag pages (with 'tag' param), Hugo uses list.html instead.
|
||||
*/}} {{ partial "header.html" . }} {{ partial "topnav.html" . }}
|
||||
*/}}
|
||||
|
||||
{{/* Extract product and version from URL path for download buttons */}}
|
||||
{{/* Example: /influxdb3/clustered/api/ → ["", "influxdb3", "clustered", "api", ""] */}}
|
||||
{{ $pathParts := split .RelPermalink "/" }}
|
||||
{{ $version := "" }}
|
||||
{{ if ge (len $pathParts) 3 }}
|
||||
{{ $version = index $pathParts 2 }}
|
||||
{{ end }}
|
||||
|
||||
{{ partial "header.html" . }} {{ partial "topnav.html" . }}
|
||||
|
||||
<div class="page-wrapper">
|
||||
{{ partial "sidebar.html" . }}
|
||||
|
|
@ -16,6 +26,26 @@ RapiDoc renderer. For tag pages (with 'tag' param), Hugo uses list.html instead.
|
|||
{{ end }}
|
||||
</header>
|
||||
|
||||
{{/* Dual download buttons for Clustered and Cloud Dedicated */}}
|
||||
{{ if or (eq $version "clustered") (eq $version "cloud-dedicated") }}
|
||||
<div class="api-spec-actions api-spec-actions--dual">
|
||||
<a href="/openapi/influxdb-{{ $version }}-v2-data-api.yml" class="btn api-spec-download" download>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
||||
<path d="M8 12L3 7h3V2h4v5h3L8 12z"/>
|
||||
<path d="M1 14h14v2H1v-2z"/>
|
||||
</svg>
|
||||
Download Data API Spec
|
||||
</a>
|
||||
<a href="/openapi/influxdb-{{ $version }}-management-api.yml" class="btn api-spec-download" download>
|
||||
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
||||
<path d="M8 12L3 7h3V2h4v5h3L8 12z"/>
|
||||
<path d="M1 14h14v2H1v-2z"/>
|
||||
</svg>
|
||||
Download Management API Spec
|
||||
</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{/* SECTION INDEX - Show intro content then tag-based children */}} {{
|
||||
with .Content }}
|
||||
<section class="api-section-content">{{ . }}</section>
|
||||
|
|
@ -32,3 +62,25 @@ RapiDoc renderer. For tag pages (with 'tag' param), Hugo uses list.html instead.
|
|||
</div>
|
||||
|
||||
{{ partial "footer.html" . }}
|
||||
|
||||
<style>
|
||||
/* Dual download buttons container for Clustered/Cloud Dedicated */
|
||||
.api-spec-actions--dual {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.75rem;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
/* Responsive - stack buttons on smaller screens */
|
||||
@media (max-width: 600px) {
|
||||
.api-spec-actions--dual {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.api-spec-actions--dual .api-spec-download {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in New Issue