mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 07:47:54 +00:00
openapi: remove / from the end of baseUri & friends #804
This commit is contained in:
parent
131b3a9a01
commit
f76f75b57b
3 changed files with 32 additions and 32 deletions
|
@ -28,9 +28,13 @@
|
|||
<link href="{{"css/ie.css" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
|
||||
<script src="{{"js/url.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 id="R-inline-script" data-root-url="/">
|
||||
{{ "// hack to let hugo tell us how to get to the root when using relativeURLs, it needs to be called *url= for it to do its magic:" | safeJS }}
|
||||
{{ "// https://github.com/gohugoio/hugo/blob/145b3fcce35fbac25c7033c91c1b7ae6d1179da8/transform/urlreplacers/absurlreplacer.go#L72" | safeJS }}
|
||||
var root_url=document.querySelector( '#R-inline-script' ).dataset.rootUrl;
|
||||
window.relearn = window.relearn || {};
|
||||
window.relearn.baseUri=root_url.replace(/\/*$/, '');
|
||||
window.relearn.baseUriFull='{{ .Site.BaseURL | safeJS }}/'.replace(/\/*$/, '');
|
||||
{{- 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 }};
|
||||
|
@ -38,10 +42,6 @@
|
|||
{{- with .Site.Home.OutputFormats.Get "search" }}
|
||||
window.index_js_url={{ "index.search.js" | relLangURL }};
|
||||
{{- end }}
|
||||
var root_url="/";
|
||||
window.relearn = window.relearn || {};
|
||||
window.relearn.baseUri=root_url.replace(/\/$/, '');
|
||||
window.relearn.baseUriFull='{{ trim .Site.BaseURL "/" | safeJS }}/';
|
||||
{{ "// variant stuff" | safeJS }}
|
||||
window.relearn.themeVariantModifier='{{ $themevariantmodifier }}';
|
||||
{{- $quotedthemevariants := slice }}
|
||||
|
|
|
@ -127,21 +127,21 @@ function switchTab(tabGroup, tabId) {
|
|||
|
||||
// Store the selection to make it persistent
|
||||
if(window.localStorage){
|
||||
var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"tab-selections");
|
||||
var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"/tab-selections");
|
||||
if(selectionsJSON){
|
||||
var tabSelections = JSON.parse(selectionsJSON);
|
||||
}else{
|
||||
var tabSelections = {};
|
||||
}
|
||||
tabSelections[tabGroup] = tabId;
|
||||
window.localStorage.setItem(window.relearn.baseUriFull+"tab-selections", JSON.stringify(tabSelections));
|
||||
window.localStorage.setItem(window.relearn.baseUriFull+"/tab-selections", JSON.stringify(tabSelections));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function restoreTabSelections() {
|
||||
if(window.localStorage){
|
||||
var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"tab-selections");
|
||||
var selectionsJSON = window.localStorage.getItem(window.relearn.baseUriFull+"/tab-selections");
|
||||
if(selectionsJSON){
|
||||
var tabSelections = JSON.parse(selectionsJSON);
|
||||
}else{
|
||||
|
@ -299,7 +299,7 @@ function initMermaid( update, attrs ) {
|
|||
|
||||
var search;
|
||||
if( update ){
|
||||
search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
|
||||
search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
||||
unmark();
|
||||
}
|
||||
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
|
||||
|
@ -351,7 +351,7 @@ function initMermaid( update, attrs ) {
|
|||
});
|
||||
}
|
||||
if( update && search && search.length ){
|
||||
sessionStorage.setItem( window.relearn.baseUriFull+'search-value', search );
|
||||
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', search );
|
||||
mark();
|
||||
}
|
||||
}
|
||||
|
@ -1128,7 +1128,7 @@ function initExpand(){
|
|||
}
|
||||
|
||||
function clearHistory() {
|
||||
var visitedItem = window.relearn.baseUriFull + 'visited-url/'
|
||||
var visitedItem = window.relearn.baseUriFull + '/visited-url/'
|
||||
for( var item in sessionStorage ){
|
||||
if( item.substring( 0, visitedItem.length ) === visitedItem ){
|
||||
sessionStorage.removeItem( item );
|
||||
|
@ -1144,7 +1144,7 @@ function clearHistory() {
|
|||
}
|
||||
|
||||
function initHistory() {
|
||||
var visitedItem = window.relearn.baseUriFull + 'visited-url/'
|
||||
var visitedItem = window.relearn.baseUriFull + '/visited-url/'
|
||||
sessionStorage.setItem( visitedItem+document.querySelector( 'body' ).dataset.url, 1);
|
||||
|
||||
// loop through the sessionStorage and see if something should be marked as visited
|
||||
|
@ -1211,7 +1211,7 @@ function scrollToPositions() {
|
|||
return;
|
||||
}
|
||||
|
||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
|
||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
||||
if( search && search.length ){
|
||||
search = regexEscape( search );
|
||||
var found = elementContains( search, elc );
|
||||
|
@ -1257,7 +1257,7 @@ function mark() {
|
|||
bodyInnerLinks[i].classList.add( 'highlight' );
|
||||
}
|
||||
|
||||
var value = sessionStorage.getItem( window.relearn.baseUriFull + 'search-value' );
|
||||
var value = sessionStorage.getItem( window.relearn.baseUriFull + '/search-value' );
|
||||
var highlightableElements = document.querySelectorAll( '.highlightable' );
|
||||
highlight( highlightableElements, value, { element: 'mark' } );
|
||||
|
||||
|
@ -1345,7 +1345,7 @@ function highlightNode( node, re, nodeName, className ){
|
|||
};
|
||||
|
||||
function unmark() {
|
||||
sessionStorage.removeItem( window.relearn.baseUriFull + 'search-value' );
|
||||
sessionStorage.removeItem( window.relearn.baseUriFull + '/search-value' );
|
||||
var markedElements = document.querySelectorAll( 'mark' );
|
||||
for( var i = 0; i < markedElements.length; i++ ){
|
||||
var parent = markedElements[i].parentNode;
|
||||
|
@ -1411,7 +1411,7 @@ function elementContains( txt, e ){
|
|||
function searchInputHandler( value ){
|
||||
unmark();
|
||||
if( value.length ){
|
||||
sessionStorage.setItem( window.relearn.baseUriFull+'search-value', value );
|
||||
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', value );
|
||||
mark();
|
||||
}
|
||||
}
|
||||
|
@ -1423,7 +1423,7 @@ function initSearch() {
|
|||
e.addEventListener( 'keydown', function( event ){
|
||||
if( event.key == 'Escape' ){
|
||||
var input = event.target;
|
||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
|
||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
||||
if( !search || !search.length ){
|
||||
input.blur();
|
||||
}
|
||||
|
@ -1463,13 +1463,13 @@ function initSearch() {
|
|||
var urlParams = new URLSearchParams( window.location.search );
|
||||
var value = urlParams.get( 'search-by' );
|
||||
if( value ){
|
||||
sessionStorage.setItem( window.relearn.baseUriFull+'search-value', value );
|
||||
sessionStorage.setItem( window.relearn.baseUriFull+'/search-value', value );
|
||||
}
|
||||
mark();
|
||||
|
||||
// set initial search value for inputs on page load
|
||||
if( sessionStorage.getItem( window.relearn.baseUriFull+'search-value' ) ){
|
||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'search-value' );
|
||||
if( sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' ) ){
|
||||
var search = sessionStorage.getItem( window.relearn.baseUriFull+'/search-value' );
|
||||
inputs.forEach( function( e ){
|
||||
e.value = search;
|
||||
var event = document.createEvent( 'Event' );
|
||||
|
|
|
@ -42,7 +42,7 @@ var variants = {
|
|||
|
||||
init: function( variants ){
|
||||
this.variants = variants;
|
||||
var variant = window.localStorage.getItem( window.relearn.baseUriFull+'variant' ) || ( this.variants.length ? this.variants[0] : '' );
|
||||
var variant = window.localStorage.getItem( window.relearn.baseUriFull+'/variant' ) || ( this.variants.length ? this.variants[0] : '' );
|
||||
this.changeVariant( variant );
|
||||
document.addEventListener( 'readystatechange', function(){
|
||||
if( document.readyState == 'interactive' ){
|
||||
|
@ -57,7 +57,7 @@ var variants = {
|
|||
|
||||
setVariant: function( variant ){
|
||||
this.variant = variant;
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'variant', variant );
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'/variant', variant );
|
||||
},
|
||||
|
||||
isVariantLoaded: function(){
|
||||
|
@ -95,11 +95,11 @@ var variants = {
|
|||
},
|
||||
|
||||
addCustomVariantOption: function(){
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariantbase' );
|
||||
if( this.variants.indexOf( variantbase ) < 0 ){
|
||||
variantbase = '';
|
||||
}
|
||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'customvariant' ) ){
|
||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' ) ){
|
||||
variantbase = '';
|
||||
}
|
||||
if( !variantbase ){
|
||||
|
@ -136,15 +136,15 @@ var variants = {
|
|||
|
||||
saveCustomVariant: function(){
|
||||
if( this.getVariant() != this.customvariantname ){
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'customvariantbase', this.getVariant() );
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'/customvariantbase', this.getVariant() );
|
||||
}
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'customvariant', this.generateStylesheet() );
|
||||
window.localStorage.setItem( window.relearn.baseUriFull+'/customvariant', this.generateStylesheet() );
|
||||
this.setVariant( this.customvariantname );
|
||||
this.markSelectedVariant();
|
||||
},
|
||||
|
||||
loadCustomVariant: function(){
|
||||
var stylesheet = window.localStorage.getItem( window.relearn.baseUriFull+'customvariant' );
|
||||
var stylesheet = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' );
|
||||
|
||||
// temp styles to document
|
||||
var head = document.querySelector( 'head' );
|
||||
|
@ -170,10 +170,10 @@ var variants = {
|
|||
},
|
||||
|
||||
resetVariant: function(){
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariantbase' );
|
||||
if( variantbase && confirm( 'You have made changes to your custom variant. Are you sure you want to reset all changes?' ) ){
|
||||
window.localStorage.removeItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
window.localStorage.removeItem( window.relearn.baseUriFull+'customvariant' );
|
||||
window.localStorage.removeItem( window.relearn.baseUriFull+'/customvariantbase' );
|
||||
window.localStorage.removeItem( window.relearn.baseUriFull+'/customvariant' );
|
||||
this.removeCustomVariantOption();
|
||||
if( this.getVariant() == this.customvariantname ){
|
||||
this.changeVariant( variantbase );
|
||||
|
@ -205,11 +205,11 @@ var variants = {
|
|||
|
||||
changeVariant: function( variant ){
|
||||
if( variant == this.customvariantname ){
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'customvariantbase' );
|
||||
var variantbase = window.localStorage.getItem( window.relearn.baseUriFull+'/customvariantbase' );
|
||||
if( this.variants.indexOf( variantbase ) < 0 ){
|
||||
variant = '';
|
||||
}
|
||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'customvariant' ) ){
|
||||
if( !window.localStorage.getItem( window.relearn.baseUriFull+'/customvariant' ) ){
|
||||
variant = '';
|
||||
}
|
||||
this.setVariant( variant );
|
||||
|
|
Loading…
Reference in a new issue