[theme] introduce relBaseUri #813

This commit is contained in:
Sören Weber 2024-03-18 21:58:53 +01:00
parent 94ce982039
commit c5ca529817
No known key found for this signature in database
GPG key ID: BEC6D55545451B6D
3 changed files with 13 additions and 2 deletions

View file

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

View file

@ -31,6 +31,7 @@
<script>
window.relearn = window.relearn || {};
window.relearn.relBasePath='{{ partial "relBasePath.hugo" $page | safeJS }}';
window.relearn.relBaseUri='{{ partial "relBaseUri.hugo" $page | safeJS }}';
window.relearn.absBaseUri='{{ replaceRE "/*$" "" .Site.BaseURL | 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 }}

View file

@ -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', window.relearn.baseUri + page.uri);
divsuggestion.setAttribute('href', window.relearn.relBaseUri + 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', window.relearn.baseUri + page.uri);
divsuggestion.setAttribute('data-uri', window.relearn.relBaseUri + page.uri);
divsuggestion.setAttribute('data-context', context);
var divtitle = document.createElement('div');
divtitle.className = 'title';