From 2edbf2645cf4d46a5cc93f32727fae625150af88 Mon Sep 17 00:00:00 2001 From: Helder Pereira Date: Tue, 24 Aug 2021 23:36:26 +0100 Subject: [PATCH] Fix search with relativeURLs --- layouts/index.json | 2 +- layouts/partials/search.html | 10 +++++----- static/js/search.js | 8 ++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/layouts/index.json b/layouts/index.json index 367f3b3185..e975d70c43 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -2,7 +2,7 @@ {{- if ne $page.Type "json" -}} {{- if and $index (gt $index 0) -}},{{- end }} { - "uri": "{{ $page.Permalink }}", + "uri": "{{ $page.RelPermalink }}", "title": "{{ htmlEscape $page.Title}}", "tags": [{{ range $tindex, $tag := $page.Params.tags }}{{ if $tindex }}, {{ end }}"{{ $tag| htmlEscape }}"{{ end }}], "description": "{{ htmlEscape .Description}}", diff --git a/layouts/partials/search.html b/layouts/partials/search.html index 41daf84b9c..bfc2b88d94 100644 --- a/layouts/partials/search.html +++ b/layouts/partials/search.html @@ -7,10 +7,10 @@ diff --git a/static/js/search.js b/static/js/search.js index 3189705e08..841fc6b888 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -6,12 +6,8 @@ function endsWith(str, suffix) { // Initialize lunrjs using our generated index file function initLunr() { - if (!endsWith(baseurl,"/")){ - baseurl = baseurl+'/' - }; - // First retrieve the index file - $.getJSON(baseurl +"index.json") + $.getJSON(index_url) .done(function(index) { pagesIndex = index; // Set up lunrjs by declaring the fields we use @@ -82,7 +78,7 @@ $( document ).ready(function() { divsuggestion.className = "autocomplete-suggestion"; divsuggestion.setAttribute("data-term", term); 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.innerText = 'ยป ' + item.title; divsuggestion.appendChild(divcontext);