Jekyll. Пошук по сайту.

Jekyll logo
Останній костиль у блог - пошук по сайту. Є 3 варіанти: Google Custom Search Engine, Lunr.js та Simple Jekyll Search. Lunr читав має проблеми з пошуком на кирилиці, тому не видумуючи велосипед для початку пробую використовувати те що вже є в самому jekyll
Зроблено по статті .

  • У корені блогу створюємо search.json з наступним вмістом
        ---
        ---
        [
          {% for post in site.posts %}
            {

              "title"    : "{{ post.title | escape }}",
              "url"      : "{{ site.baseurl }}{{ post.url }}",
              "category" : "{{ post.category }}",
              "tags"     : "{{ post.tags | join: ', ' }}",
              "date"     : "{{ post.date }}"

            } {% unless forloop.last %},{% endunless %}
          {% endfor %}
        ]
        
  • Зберігаємо search-script.js ;
  • Створюємо шаблонну сторінку пошуку, чи додаємо наступний код до шаблону
        <!-- Html Elements for Search -->
        <div id="search-container">
        <input type="text" id="search-input" placeholder="search...">
        <ul id="results-container">
        </div>

        <!-- Script pointing to search-script.js -->
        <script src="/path/to/search-script.js" type="text/javascript"></script>

        <!-- Configuration -->
        <script>
        SimpleJekyllSearch({
          searchInput: document.getElementById('search-input'),
          resultsContainer: document.getElementById('results-container'),
          json: '/search.json'
        })
        </script>

Готово.