2023-07-27 16:14:55 +02:00
|
|
|
{{- $page := .page }}
|
|
|
|
{{- if and (not $page) .context }}
|
|
|
|
{{- $page = .context }}
|
2024-09-29 23:54:17 +02:00
|
|
|
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'openapi' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $page.File.Filename }}
|
2023-07-27 16:14:55 +02:00
|
|
|
{{- end }}
|
2024-05-28 22:17:36 +02:00
|
|
|
{{- $u := urls.Parse .src }}
|
|
|
|
{{- $src := $u.String }}
|
2024-03-17 00:27:38 +01:00
|
|
|
{{- $spec := "" }}
|
2024-08-29 12:28:34 +02:00
|
|
|
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "_relearn/makeRandomMd5.gotmpl" $page) .id }}
|
2025-01-29 18:03:23 +01:00
|
|
|
{{- if $u.IsAbs }}
|
|
|
|
{{- partialCached "_relearn/urlExists.gotmpl" (dict "url" .src "page" $page "type" "OpenAPI spec link") $u.String }}
|
|
|
|
{{- else }}
|
2024-05-28 22:17:36 +02:00
|
|
|
{{- $path := strings.TrimPrefix "./" $u.Path }}
|
|
|
|
{{- with or
|
|
|
|
($page.Resources.Get $path)
|
|
|
|
(resources.Get $path)
|
|
|
|
}}
|
|
|
|
{{- $src = "" }}
|
|
|
|
{{- $spec = .Content }}
|
|
|
|
{{- else }}
|
2025-01-29 20:37:08 +01:00
|
|
|
{{- $msg := printf "%q: OpenAPI spec '%s' is not a resource" $page.File.Filename .src }}
|
2025-01-29 22:17:39 +01:00
|
|
|
{{- partial "_relearn/urlErrorReport.gotmpl" (dict "url" .src "page" $page "param" "openapi" "msg" $msg) }}
|
2024-05-28 22:17:36 +02:00
|
|
|
{{- end }}
|
2023-05-14 23:05:07 +02:00
|
|
|
{{- end }}
|
2024-09-05 20:02:38 +02:00
|
|
|
{{- with $page -}}
|
2023-05-14 23:05:07 +02:00
|
|
|
<div class="sc-openapi-wrapper is-loading helper-loading-container">
|
|
|
|
<div
|
|
|
|
class="sc-openapi-container"
|
2023-09-23 10:18:31 +02:00
|
|
|
id="R-openapi-{{ $id }}"
|
2023-09-21 21:34:02 +02:00
|
|
|
data-openapi-url="{{ $src }}"
|
2024-03-17 00:27:38 +01:00
|
|
|
data-openapi-spec="{{ $spec | safeHTMLAttr }}"
|
2023-05-14 23:05:07 +02:00
|
|
|
></div>
|
|
|
|
</div>
|
2023-10-09 17:42:51 +02:00
|
|
|
{{- .Store.Set "hasOpenApi" true }}
|
2023-05-14 23:05:07 +02:00
|
|
|
{{- end }}
|