Skip to content

Commit

Permalink
Fixed changing language from search
Browse files Browse the repository at this point in the history
Signed-off-by: George Araújo <[email protected]>
  • Loading branch information
george-gca committed Jan 18, 2025
1 parent 1537d51 commit a685d62
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion _includes/scripts.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@
</div>
</ninja-keys>
<script src="{{ '/assets/js/search-setup.js' | relative_url | bust_file_cache }}"></script>
<script src="{% if site.active_lang != site.default_lang %}{{ '/assets/js/search-data.js' | prepend: site.active_lang | relative_url }}{% else %}{{ '/assets/js/search-data.js' | relative_url }}{% endif %}"></script>
<script
src="{% if site.active_lang != site.default_lang %}{{ '/assets/js/search-data.js' | prepend: site.active_lang | relative_url }}{% else %}{{ '/assets/js/search-data.js' | relative_url }}{% endif %}"
></script>
<script src="{{ '/assets/js/shortcut-key.js' | relative_url | bust_file_cache }}"></script>
{% endif %}

Expand Down
14 changes: 12 additions & 2 deletions _scripts/search.liquid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ permalink: /assets/js/search-data.js
{% else %}
{% assign lang = site.active_lang %}
{% endif %}
const currentUrl = window.location.href;
const siteUrl = "{{ site.url }}";
let updatedUrl = currentUrl.replace("{{ site.url }}{{ site.baseurl }}", "");
if (currentUrl.length == updatedUrl.length && currentUrl.startsWith("http://127.0.0.1")) {
const otherSiteUrl = siteUrl.replace("localhost", "127.0.0.1");
updatedUrl = currentUrl.replace(otherSiteUrl + "{{ site.baseurl }}", "");
}
if ("{{ lang }}".length > 0) {
updatedUrl = updatedUrl.replace("/{{ lang }}", "");
}
// get the ninja-keys element
const ninja = document.querySelector('ninja-keys');

Expand Down Expand Up @@ -307,7 +317,7 @@ ninja.data = [
title: '{{ l }}',
section: '{{ site.data[site.active_lang].strings.search.languages }}',
handler: () => {
window.location.href = "{{ site.baseurl }}{{ page.url }}";
window.location.href = "{{ site.baseurl }}" + updatedUrl;
},
},
{%- else -%}
Expand All @@ -316,7 +326,7 @@ ninja.data = [
title: '{{ l }}',
section: '{{ site.data[site.active_lang].strings.search.languages }}',
handler: () => {
window.location.href = "{{ site.baseurl }}/{{ l }}{{ page.url }}";
window.location.href = "{{ site.baseurl }}/{{ l }}" + updatedUrl;
},
},
{%- endif -%}
Expand Down

0 comments on commit a685d62

Please sign in to comment.