Hi, there. I’m new to jekyll and programming.
I’ve adapted a theme to build a personal website in 3 languages. Basically, I’ve created the variable lang
that distinguishes the pages between br, en and es languages.
But I’m having a hard time figuring out how to filter the pages to use a search function. Basically, there’s a search button in the header, which is a window search panel, that searches for any post. I’d like to filter it in a way that if the current user’s page has a variable lang: br
, then if she searches something, it will only show results in br (i.e., posts with the same variable lang: br
). The problem is that it is showing posts in every language.
The theme has a JS document (I don’t know anything about js) that I guess is working on the search data, which is the following:
window.TEXT_SEARCH_DATA={
{%- for _collection in site.collections -%}
{%- unless forloop.first -%},{%- endunless -%}
'{{ _collection.label }}':[
{%- for _article in _collection.docs -%}
{%- unless forloop.first -%},{%- endunless -%}
{'title':{{ _article.title | jsonify }},
{%- include snippets/prepend-baseurl.html path=_article.url -%}
{%- assign _url = __return -%}
'url':{{ _url | jsonify }}}
{%- endfor -%}
]
{%- endfor -%}
};
I’ve tried to filter it with liquid. The closer I get was by adding the line {%- assign _collection = _collection1.docs | where: 'lang', page.lang -%}
after '{{ _collection.label }}':[
. This way, it filtered only the br posts (I have no idea why), but didn’t showed posts in english or spanish (even if the current page’s lang is en or es).
Does anyone have any tips?
Notes:
site: gustavosabbag.github.io (to test, you can type p
in the search button, there is test posts in english and portuguese)
repo: https://github.com/gustavosabbag/gustavosabbag.github.io/blob/master/_includes/search-providers/default/search-data.js (in the file aforementioned)
There’s another JS that I suppose is calling this function and may have something to do with it: https://github.com/gustavosabbag/gustavosabbag.github.io/blob/master/_includes/search-providers/default/search.js
Thank you for any help