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 }} {{- $page := .page }}
{{- with $page }} {{- with $page }}
{{- $urlOpenapi := "" }} {{- $urlOpenapi := "" }}
{{- $relOpenapi := "" }}
{{- $cssInProject := false }}
{{- if and (isset .Params "customopenapiurl") .Params.customOpenapiURL }} {{- if and (isset .Params "customopenapiurl") .Params.customOpenapiURL }}
{{- $urlOpenapi = .Params.customOpenapiURL }} {{- $urlOpenapi = .Params.customOpenapiURL }}
{{- $relOpenapi = .Params.customOpenapiURL }}
{{- else if and (isset .Site.Params "customopenapiurl") .Site.Params.customOpenapiURL }} {{- else if and (isset .Site.Params "customopenapiurl") .Site.Params.customOpenapiURL }}
{{- $urlOpenapi = .Site.Params.customOpenapiURL }} {{- $urlOpenapi = .Site.Params.customOpenapiURL }}
{{- $relOpenapi = .Site.Params.customOpenapiURL }}
{{- else }} {{- else }}
{{- $urlOpenapi = "js/swagger-ui/swagger-ui-bundle.js" | relURL }} {{- $urlOpenapi = printf "%s%s" ("js/swagger-ui/swagger-ui-bundle.js" | relURL) (cond .Site.Params.disableAssetsBusting "" (printf "?%d" now.Unix)) }}
{{- if not .Site.Params.disableAssetsBusting }} {{- $relOpenapi = printf "%s%s" ("/js/swagger-ui/swagger-ui-bundle.js") (cond .Site.Params.disableAssetsBusting "" (printf "?%d" now.Unix)) }}
{{- $urlOpenapi = printf "%s?%d" $urlOpenapi now.Unix }} {{- $cssInProject = true }}
{{- end }} {{- end }}
{{- end }}
<script>window.noZensmooth = true;</script> <script>window.noZensmooth = true;</script>
<script src="{{ $urlOpenapi }}" defer></script> <script src="{{ $urlOpenapi }}" defer></script>
{{- $urlOpenapi := replace $urlOpenapi "swagger-ui-bundle" "swagger-ui-standalone-preset" }} {{- $urlOpenapi := replace $urlOpenapi "swagger-ui-bundle" "swagger-ui-standalone-preset" }}
<script src="{{ $urlOpenapi }}" defer></script> <script src="{{ $urlOpenapi }}" defer></script>
{{- $urlOpenapi := replace $urlOpenapi "swagger-ui-standalone-preset" "swagger-ui" }} {{- $relOpenapi := replace $relOpenapi "swagger-ui-bundle" "swagger-ui" }}
{{- $urlOpenapi := replace $urlOpenapi ".js" ".css" }} {{- $relOpenapi := replace $relOpenapi ".js" ".css" }}
<script> <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> </script>
{{- end }} {{- end }}

View file

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

View file

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