mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
Merge branch 'helfper-fix-relative-search' into 2.0.0
This commit is contained in:
commit
96c98986a4
3 changed files with 8 additions and 12 deletions
|
@ -2,7 +2,7 @@
|
||||||
{{- if ne $page.Type "json" -}}
|
{{- if ne $page.Type "json" -}}
|
||||||
{{- if and $index (gt $index 0) -}},{{- end }}
|
{{- if and $index (gt $index 0) -}},{{- end }}
|
||||||
{
|
{
|
||||||
"uri": "{{ $page.Permalink }}",
|
"uri": "{{ $page.RelPermalink }}",
|
||||||
"title": "{{ htmlEscape $page.Title}}",
|
"title": "{{ htmlEscape $page.Title}}",
|
||||||
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
|
"tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}],
|
||||||
"description": "{{ htmlEscape .Description}}",
|
"description": "{{ htmlEscape .Description}}",
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
<script type="text/javascript" src="{{"js/lunr.min.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
|
<script type="text/javascript" src="{{"js/lunr.min.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
|
||||||
<script type="text/javascript" src="{{"js/auto-complete.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
|
<script type="text/javascript" src="{{"js/auto-complete.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{{ if .Site.IsMultiLingual }}
|
// 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:
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
// https://github.com/gohugoio/hugo/blob/145b3fcce35fbac25c7033c91c1b7ae6d1179da8/transform/urlreplacers/absurlreplacer.go#L72
|
||||||
{{ else }}
|
var index_url={{"index.json" | relLangURL}};
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
var root_url="/";
|
||||||
{{ end }}
|
var baseUri=root_url.replace(/\/$/, '');
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="{{"js/search.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
|
<script type="text/javascript" src="{{"js/search.js" | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
|
||||||
|
|
|
@ -6,12 +6,8 @@ function endsWith(str, suffix) {
|
||||||
|
|
||||||
// Initialize lunrjs using our generated index file
|
// Initialize lunrjs using our generated index file
|
||||||
function initLunr() {
|
function initLunr() {
|
||||||
if (!endsWith(baseurl,"/")){
|
|
||||||
baseurl = baseurl+'/'
|
|
||||||
};
|
|
||||||
|
|
||||||
// First retrieve the index file
|
// First retrieve the index file
|
||||||
$.getJSON(baseurl +"index.json")
|
$.getJSON(index_url)
|
||||||
.done(function(index) {
|
.done(function(index) {
|
||||||
pagesIndex = index;
|
pagesIndex = index;
|
||||||
// Set up lunrjs by declaring the fields we use
|
// Set up lunrjs by declaring the fields we use
|
||||||
|
@ -82,7 +78,7 @@ $( document ).ready(function() {
|
||||||
divsuggestion.className = "autocomplete-suggestion";
|
divsuggestion.className = "autocomplete-suggestion";
|
||||||
divsuggestion.setAttribute("data-term", term);
|
divsuggestion.setAttribute("data-term", term);
|
||||||
divsuggestion.setAttribute("data-title", item.title);
|
divsuggestion.setAttribute("data-title", item.title);
|
||||||
divsuggestion.setAttribute("data-uri", item.uri);
|
divsuggestion.setAttribute("data-uri", baseUri + item.uri);
|
||||||
divsuggestion.setAttribute("data-context", item.context);
|
divsuggestion.setAttribute("data-context", item.context);
|
||||||
divsuggestion.innerText = '» ' + item.title;
|
divsuggestion.innerText = '» ' + item.title;
|
||||||
divsuggestion.appendChild(divcontext);
|
divsuggestion.appendChild(divcontext);
|
||||||
|
|
Loading…
Reference in a new issue