Skip to content

Commit

Permalink
[theme] introduce relBaseUri #813
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Mar 18, 2024
1 parent 94ce982 commit c5ca529
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
10 changes: 10 additions & 0 deletions layouts/partials/relBaseUri.hugo
Original file line number Diff line number Diff line change
@@ -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 }}
1 change: 1 addition & 0 deletions layouts/partials/stylesheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
4 changes: 2 additions & 2 deletions static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit c5ca529

Please sign in to comment.