mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
[theme] introduce relBaseUri #813
This commit is contained in:
parent
94ce982039
commit
c5ca529817
3 changed files with 13 additions and 2 deletions
10
layouts/partials/relBaseUri.hugo
Normal file
10
layouts/partials/relBaseUri.hugo
Normal 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 }}
|
|
@ -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 }}
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in a new issue