From 131b3a9a01f6cd4a61934fdb3bb23671c214ff9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sat, 16 Mar 2024 12:56:56 +0100 Subject: [PATCH] openapi: fix theme switch #804 --- layouts/partials/menu.html | 2 +- layouts/partials/stylesheet.html | 2 +- static/js/search.js | 4 ++-- static/js/theme.js | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/layouts/partials/menu.html b/layouts/partials/menu.html index a2ccaf7cf1..c2c60e6f89 100644 --- a/layouts/partials/menu.html +++ b/layouts/partials/menu.html @@ -73,7 +73,7 @@  
- {{- $page := .Page }} {{- $pageLang := .Page.Language.Lang }} {{- range .Page.AllTranslations }} diff --git a/layouts/partials/stylesheet.html b/layouts/partials/stylesheet.html index fe04fca021..90fdf5c0da 100644 --- a/layouts/partials/stylesheet.html +++ b/layouts/partials/stylesheet.html @@ -39,8 +39,8 @@ window.index_js_url={{ "index.search.js" | relLangURL }}; {{- end }} var root_url="/"; - var baseUri=root_url.replace(/\/$/, ''); window.relearn = window.relearn || {}; + window.relearn.baseUri=root_url.replace(/\/$/, ''); window.relearn.baseUriFull='{{ trim .Site.BaseURL "/" | safeJS }}/'; {{ "// variant stuff" | safeJS }} window.relearn.themeVariantModifier='{{ $themevariantmodifier }}'; diff --git a/static/js/search.js b/static/js/search.js index aabaeb1265..d9ccf56bfd 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -217,7 +217,7 @@ function searchDetail( value ) { divsuggestion.className = 'autocomplete-suggestion'; divsuggestion.setAttribute('data-term', value); divsuggestion.setAttribute('data-title', page.title); - divsuggestion.setAttribute('href', baseUri + page.uri); + divsuggestion.setAttribute('href', window.relearn.baseUri + page.uri); divsuggestion.setAttribute('data-context', context); var divtitle = document.createElement('div'); divtitle.className = 'title'; @@ -289,7 +289,7 @@ function startSearch(){ divsuggestion.className = 'autocomplete-suggestion'; divsuggestion.setAttribute('data-term', term); divsuggestion.setAttribute('data-title', page.title); - divsuggestion.setAttribute('data-uri', baseUri + page.uri); + divsuggestion.setAttribute('data-uri', window.relearn.baseUri + page.uri); divsuggestion.setAttribute('data-context', context); var divtitle = document.createElement('div'); divtitle.className = 'title'; diff --git a/static/js/theme.js b/static/js/theme.js index d1e293da98..5eeb5f668c 100644 --- a/static/js/theme.js +++ b/static/js/theme.js @@ -390,6 +390,7 @@ function initOpenapi( update, attrs ){ } function renderOpenAPI(oc) { + var baseUri = window.relearn.baseUri; var mod = window.relearn.themeVariantModifier; var buster = window.themeUseOpenapi.assetsBuster ? '?' + window.themeUseOpenapi.assetsBuster : ''; var print = isPrint || attrs.isPrintPreview ? "PRINT-" : ""; @@ -1523,7 +1524,7 @@ if( window.themeUseMermaid ){ function useOpenapi( config ){ if( config.css && config.css.startsWith( '/' ) ){ - config.css = baseUri + config.css; + config.css = window.relearn.baseUri + config.css; } } if( window.themeUseOpenapi ){