Skip to content

Commit 82679eb

Browse files
committed
api: include alternate link for swagger / OpenAPI spec
The API docs are generated dynamically, which prevents them from being crawled / indexed. Provide a link to the swagger / OpenAPI spec that's used to generate the page, so that that content can be used as alternative. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent d8fcda9 commit 82679eb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

layouts/_default/api.html

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3-
3+
{{ $specURL := urls.Parse (printf "/%s%s.yaml" .File.Dir .File.ContentBaseName) }}
44
<head>
55
<title>{{ .Title }}</title>
66
<!-- needed for adaptive design -->
@@ -9,6 +9,13 @@
99
<meta charset="utf-8" />
1010
<!-- favicon -->
1111
<link rel="shortcut icon" href="/assets/images/favicon.svg" type="image/svg">
12+
<!--
13+
Provide a link to the swagger / OpenAPI spec itself. We're currently using
14+
Swagger (OpenAPI v2) for some, so use a more generic "application/yaml" type.
15+
16+
Once all our specs are updated to OpenAPI v3, we can change this to "application/vnd.oai.openapi"
17+
-->
18+
<link rel="alternate" href="{{ $specURL.String | absURL }}" type="application/yaml" title="{{ .Title }} (Swagger/OpenAPI)" />
1219
<style>
1320
body {
1421
margin: 0;
@@ -49,7 +56,12 @@
4956
</head>
5057

5158
<body>
52-
{{ $specURL := urls.Parse (printf "/%s%s.yaml" .File.Dir .File.ContentBaseName) }}
59+
<noscript>
60+
<p>
61+
This page is rendered with JavaScript.<br>
62+
<a target="_blank" href="{{ $specURL.String | absURL }}" rel="noreferrer">Download {{ .Title }} Swagger/OpenAPI specification</a>
63+
</p>
64+
</noscript>
5365
{{ if or (strings.HasPrefix .RelPermalink "/reference/api/hub/") (strings.HasPrefix .RelPermalink "/reference/api/registry/") }}
5466
<redoc spec-url="{{ $specURL.String }}" suppress-warnings="true" lazy-rendering></redoc>
5567
{{ else }}

0 commit comments

Comments
 (0)