mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
openapi: make it run for file:// protocol #806
This commit is contained in:
parent
567b930220
commit
b18bca9172
2 changed files with 16 additions and 7 deletions
|
@ -4,18 +4,21 @@
|
|||
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'openapi' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
|
||||
{{- end }}
|
||||
{{- $src := .src }}
|
||||
{{- $spec := "" }}
|
||||
{{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }}
|
||||
{{- with $page }}
|
||||
{{- with .Resources.Match $src }}
|
||||
{{- range . }}
|
||||
{{- $src = .RelPermalink }}
|
||||
{{- end }}
|
||||
{{- with or
|
||||
(.Resources.Get $src)
|
||||
(resources.Get $src)
|
||||
}}
|
||||
{{- $spec = .Content }}
|
||||
{{- end }}
|
||||
<div class="sc-openapi-wrapper is-loading helper-loading-container">
|
||||
<div
|
||||
class="sc-openapi-container"
|
||||
id="R-openapi-{{ $id }}"
|
||||
data-openapi-url="{{ $src }}"
|
||||
data-openapi-spec="{{ $spec | safeHTMLAttr }}"
|
||||
></div>
|
||||
</div>
|
||||
{{- .Store.Set "hasOpenApi" true }}
|
||||
|
|
|
@ -446,7 +446,7 @@ function initOpenapi( update, attrs ){
|
|||
const openapiPromise = new Promise( function(resolve){ resolve() });
|
||||
openapiPromise
|
||||
.then( function(){
|
||||
SwaggerUIBundle({
|
||||
var options = {
|
||||
defaultModelsExpandDepth: 2,
|
||||
defaultModelExpandDepth: 2,
|
||||
docExpansion: isPrint || attrs.isPrintPreview ? 'full' : 'list',
|
||||
|
@ -470,9 +470,15 @@ function initOpenapi( update, attrs ){
|
|||
activated: true,
|
||||
theme: swagger_code_theme,
|
||||
},
|
||||
url: oc.dataset.openapiUrl,
|
||||
validatorUrl: 'none',
|
||||
});
|
||||
};
|
||||
if( oc.dataset.openapiSpec ){
|
||||
Object.assign( options, { spec: JSON.parse( oc.dataset.openapiSpec ) });
|
||||
}
|
||||
else{
|
||||
Object.assign( options, { url: oc.dataset.openapiUrl });
|
||||
}
|
||||
SwaggerUIBundle( options );
|
||||
})
|
||||
.then( function(){
|
||||
let observerCallback = function () {
|
||||
|
|
Loading…
Reference in a new issue