openapi: there's a small fire buring in hell #804

This commit is contained in:
Sören Weber 2024-03-16 21:23:31 +01:00
parent 92a3375ae8
commit 628d6070c0
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 13 additions and 11 deletions

View file

@ -1,23 +1,26 @@
{{- $page := .page }}
{{- with $page }}
{{- $urlOpenapi := "" }}
{{- $relOpenapi := "" }}
{{- $cssInProject := false }}
{{- if and (isset .Params "customopenapiurl") .Params.customOpenapiURL }}
{{- $urlOpenapi = .Params.customOpenapiURL }}
{{- $relOpenapi = .Params.customOpenapiURL }}
{{- else if and (isset .Site.Params "customopenapiurl") .Site.Params.customOpenapiURL }}
{{- $urlOpenapi = .Site.Params.customOpenapiURL }}
{{- $relOpenapi = .Site.Params.customOpenapiURL }}
{{- else }}
{{- $urlOpenapi = "js/swagger-ui/swagger-ui-bundle.js" | relURL }}
{{- if not .Site.Params.disableAssetsBusting }}
{{- $urlOpenapi = printf "%s?%d" $urlOpenapi now.Unix }}
{{- end }}
{{- $urlOpenapi = printf "%s%s" ("js/swagger-ui/swagger-ui-bundle.js" | relURL) (cond .Site.Params.disableAssetsBusting "" (printf "?%d" now.Unix)) }}
{{- $relOpenapi = printf "%s%s" ("/js/swagger-ui/swagger-ui-bundle.js") (cond .Site.Params.disableAssetsBusting "" (printf "?%d" now.Unix)) }}
{{- $cssInProject = true }}
{{- end }}
<script>window.noZensmooth = true;</script>
<script src="{{ $urlOpenapi }}" defer></script>
{{- $urlOpenapi := replace $urlOpenapi "swagger-ui-bundle" "swagger-ui-standalone-preset" }}
<script src="{{ $urlOpenapi }}" defer></script>
{{- $urlOpenapi := replace $urlOpenapi "swagger-ui-standalone-preset" "swagger-ui" }}
{{- $urlOpenapi := replace $urlOpenapi ".js" ".css" }}
{{- $relOpenapi := replace $relOpenapi "swagger-ui-bundle" "swagger-ui" }}
{{- $relOpenapi := replace $relOpenapi ".js" ".css" }}
<script>
window.themeUseOpenapi = { css: {{ $urlOpenapi }}, assetsBuster: {{ cond (not .Site.Params.disableAssetsBusting) now.Unix 0 }} };
window.themeUseOpenapi = { css: {{ $relOpenapi }}, cssInProject: {{ $cssInProject | safeJS }}, assetsBuster: {{ cond (not .Site.Params.disableAssetsBusting) now.Unix 0 }} };
</script>
{{- end }}

View file

@ -1,8 +1,7 @@
{{- $subdir := strings.TrimSuffix (relLangURL "/") (relLangURL "") }}
{{- $url := .RelPermalink }}
{{- $url = replaceRE "/[^/]*$" "" $url }}
{{- $home_url := .Site.Home.RelPermalink }}
{{- $home_url = replaceRE "/[^/]*$" "" $home_url }}
{{- $rel_url := strings.TrimPrefix $home_url $url }}
{{- $rel_url := strings.TrimPrefix $subdir $url }}
{{- $rel_url = replaceRE "/[^/]*" "/.." $rel_url }}
{{- $rel_url = trim $rel_url "/" }}
{{- return $rel_url }}

View file

@ -1523,7 +1523,7 @@ if( window.themeUseMermaid ){
}
function useOpenapi( config ){
if( config.css && config.css.startsWith( '/' ) ){
if( config.css && config.cssInProject ){
config.css = window.relearn.baseUri + config.css;
}
}