Skip to content

Commit d3a9b25

Browse files
committed
Update search-loader.html
1 parent 9d150eb commit d3a9b25

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

_includes/search-loader.html

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
{% capture result_elem %}
77
<article class="px-1 px-sm-2 px-lg-4 px-xl-0">
88
<header>
9+
{% if site.active_lang != site.default_lang %}
10+
<h2><a {% static_href %}href="/{{ site.active_lang }}{url}"{% endstatic_href %}>{title}</a></h2>
11+
{% else %}
912
<h2><a href="{url}">{title}</a></h2>
13+
{% endif %}
1014
<div class="post-meta d-flex flex-column flex-sm-row text-muted mt-1 mb-1">
1115
{categories}
1216
{tags}
@@ -21,38 +25,31 @@ <h2><a href="{url}">{title}</a></h2>
2125
<script>
2226
{% comment %} Note: dependent library will be loaded in `js-selector.html` {% endcomment %}
2327
document.addEventListener('DOMContentLoaded', () => {
24-
// Get the current language
25-
const lang = "{{site.active_lang}}";
26-
27-
// Construct the appropriate search JSON path
28-
const searchJsonPath = lang === "{{site.default_lang}}"
29-
? '{{ "/assets/js/data/search.json" | relative_url }}'
30-
: `{{ "/" | relative_url }}${lang}/assets/js/data/search.json`;
31-
32-
// Initialize Simple Jekyll Search
28+
{% assign search_path = '/assets/js/data/search.json' %}
29+
{% if site.active_lang != site.default_lang %}
30+
{% assign search_path = '/' | append: site.active_lang | append: search_path %}
31+
{% endif %}
32+
3333
SimpleJekyllSearch({
3434
searchInput: document.getElementById('search-input'),
3535
resultsContainer: document.getElementById('search-results'),
36-
json: searchJsonPath, // Use the dynamic path based on language
36+
json: '{{ search_path | relative_url }}',
3737
searchResultTemplate: '{{ result_elem | strip_newlines }}',
3838
noResultsText: '{{ not_found }}',
3939
templateMiddleware: function(prop, value, template) {
4040
if (prop === 'categories') {
4141
if (value === '') {
42-
return `${value}`;
43-
} else {
44-
return `<div class="me-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`;
42+
return '';
4543
}
44+
return `<div class="mr-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`;
4645
}
47-
4846
if (prop === 'tags') {
4947
if (value === '') {
50-
return `${value}`;
51-
} else {
52-
return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`;
48+
return '';
5349
}
50+
return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`;
5451
}
5552
}
5653
});
5754
});
58-
</script>
55+
</script>

0 commit comments

Comments
 (0)