Skip to content

Commit

Permalink
[theme] rename baseUri to relBasePath #813
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Mar 18, 2024
1 parent a3c4d72 commit 5f40e57
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
11 changes: 11 additions & 0 deletions layouts/partials/relBasePath.hugo
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion layouts/partials/stylesheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<script src="{{"js/variant.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
<script>
window.relearn = window.relearn || {};
window.relearn.baseUri='{{ partial "toBaseRelURL.hugo" $page | safeJS }}';
window.relearn.baseUriFull='{{ replaceRE "/*$" "" .Site.BaseURL | safeJS }}';
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
{{- 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 }}
window.index_json_url={{ "index.json" | relLangURL }};
Expand Down
10 changes: 0 additions & 10 deletions layouts/partials/toBaseRelURL.hugo

This file was deleted.

10 changes: 5 additions & 5 deletions static/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,11 @@ function initOpenapi( update, attrs ){

}
function renderOpenAPI(oc) {
var baseUri = window.relearn.baseUri;
var relBasePath = window.relearn.relBasePath;
var mod = window.relearn.themeVariantModifier;
var buster = window.themeUseOpenapi.assetsBuster ? '?' + window.themeUseOpenapi.assetsBuster : '';
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_code_theme = variants.getColorValue( print + 'OPENAPI-CODE-theme' );

Expand All @@ -418,8 +418,8 @@ function initOpenapi( update, attrs ){
'<head>' +
'<link rel="stylesheet" href="' + window.themeUseOpenapi.css + '">' +
'<link rel="stylesheet" href="' + theme + '">' +
'<link rel="stylesheet" href="' + baseUri + '/css/swagger.css' + buster + '">' +
'<link rel="stylesheet" href="' + baseUri + '/css/swagger-' + swagger_theme + '.css' + buster + '">' +
'<link rel="stylesheet" href="' + relBasePath + '/css/swagger.css' + buster + '">' +
'<link rel="stylesheet" href="' + relBasePath + '/css/swagger-' + swagger_theme + '.css' + buster + '">' +
'</head>' +
'<body>' +
'<a class="relearn-expander" href="" onclick="return relearn_collapse_all()">Collapse all</a>' +
Expand Down Expand Up @@ -1538,7 +1538,7 @@ if( window.themeUseMermaid ){

function useOpenapi( config ){
if( config.css && config.cssInProject ){
config.css = window.relearn.baseUri + config.css;
config.css = window.relearn.relBasePath + config.css;
}
}
if( window.themeUseOpenapi ){
Expand Down

0 comments on commit 5f40e57

Please sign in to comment.