[theme] rename baseUri to relBasePath #813

This commit is contained in:
Sören Weber 2024-03-18 21:56:21 +01:00
parent a3c4d72125
commit 5f40e57d17
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
4 changed files with 17 additions and 16 deletions

View file

@ -0,0 +1,11 @@
{{- /* generates an uphill path from the current page to the root of the site */}}
{{- $subdir := strings.TrimSuffix (relLangURL "/") (relLangURL "") }}
{{- $relBasePath := .RelPermalink }}
{{- $relBasePath = replaceRE "/[^/]*$" "" $relBasePath }}
{{- $relBasePath = strings.TrimPrefix $subdir $relBasePath }}
{{- $relBasePath = replaceRE "/[^/]*" "/.." $relBasePath }}
{{- $relBasePath = trim $relBasePath "/" }}
{{- if not $relBasePath }}
{{- $relBasePath = "." }}
{{- end }}
{{- return $relBasePath }}

View file

@ -30,8 +30,8 @@
<script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script> <script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
<script> <script>
window.relearn = window.relearn || {}; window.relearn = window.relearn || {};
window.relearn.baseUri='{{ partial "toBaseRelURL.hugo" $page | safeJS }}';
window.relearn.baseUriFull='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}'; window.relearn.baseUriFull='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
{{- with .Site.Home.OutputFormats.Get "json" }} {{- with .Site.Home.OutputFormats.Get "json" }}
{{- warnf "%q: DEPRECATED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" $page.File.Filename }} {{- warnf "%q: DEPRECATED usage of 'json' output format found, use 'search' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/customization#activate-search" $page.File.Filename }}
window.index_json_url={{ "index.json" | relLangURL }}; window.index_json_url={{ "index.json" | relLangURL }};

View file

@ -1,10 +0,0 @@
{{- $subdir := strings.TrimSuffix (relLangURL "/") (relLangURL "") }}
{{- $url := .RelPermalink }}
{{- $url = replaceRE "/[^/]*$" "" $url }}
{{- $rel_url := strings.TrimPrefix $subdir $url }}
{{- $rel_url = replaceRE "/[^/]*" "/.." $rel_url }}
{{- $rel_url = trim $rel_url "/" }}
{{- if not $rel_url }}
{{- $rel_url = "." }}
{{- end }}
{{- return $rel_url }}

View file

@ -390,11 +390,11 @@ function initOpenapi( update, attrs ){
} }
function renderOpenAPI(oc) { function renderOpenAPI(oc) {
var baseUri = window.relearn.baseUri; var relBasePath = window.relearn.relBasePath;
var mod = window.relearn.themeVariantModifier; var mod = window.relearn.themeVariantModifier;
var buster = window.themeUseOpenapi.assetsBuster ? '?' + window.themeUseOpenapi.assetsBuster : ''; var buster = window.themeUseOpenapi.assetsBuster ? '?' + window.themeUseOpenapi.assetsBuster : '';
var print = isPrint || attrs.isPrintPreview ? "PRINT-" : ""; var print = isPrint || attrs.isPrintPreview ? "PRINT-" : "";
var theme = print ? `${baseUri}/css/theme-relearn-light${mod}.css${buster}` : document.querySelector( '#R-variant-style' ).attributes.href.value var theme = print ? `${relBasePath}/css/theme-relearn-light${mod}.css${buster}` : document.querySelector( '#R-variant-style' ).attributes.href.value
var swagger_theme = variants.getColorValue( print + 'OPENAPI-theme' ); var swagger_theme = variants.getColorValue( print + 'OPENAPI-theme' );
var swagger_code_theme = variants.getColorValue( print + 'OPENAPI-CODE-theme' ); var swagger_code_theme = variants.getColorValue( print + 'OPENAPI-CODE-theme' );
@ -418,8 +418,8 @@ function initOpenapi( update, attrs ){
'<head>' + '<head>' +
'<link rel="stylesheet" href="' + window.themeUseOpenapi.css + '">' + '<link rel="stylesheet" href="' + window.themeUseOpenapi.css + '">' +
'<link rel="stylesheet" href="' + theme + '">' + '<link rel="stylesheet" href="' + theme + '">' +
'<link rel="stylesheet" href="' + baseUri + '/css/swagger.css' + buster + '">' + '<link rel="stylesheet" href="' + relBasePath + '/css/swagger.css' + buster + '">' +
'<link rel="stylesheet" href="' + baseUri + '/css/swagger-' + swagger_theme + '.css' + buster + '">' + '<link rel="stylesheet" href="' + relBasePath + '/css/swagger-' + swagger_theme + '.css' + buster + '">' +
'</head>' + '</head>' +
'<body>' + '<body>' +
'<a class="relearn-expander" href="" onclick="return relearn_collapse_all()">Collapse all</a>' + '<a class="relearn-expander" href="" onclick="return relearn_collapse_all()">Collapse all</a>' +
@ -1538,7 +1538,7 @@ if( window.themeUseMermaid ){
function useOpenapi( config ){ function useOpenapi( config ){
if( config.css && config.cssInProject ){ if( config.css && config.cssInProject ){
config.css = window.relearn.baseUri + config.css; config.css = window.relearn.relBasePath + config.css;
} }
} }
if( window.themeUseOpenapi ){ if( window.themeUseOpenapi ){