Instant search - description not showing

Hello everyone,

I recently started using jekyll to build a little Documentation/Knowledge Base website.

I found this theme which fits my needs and started working with it.

Since the search wasnt live I tried to find a good alternative and found this tutorial. So far its working good, the only issue I have is that the search isnt showing the description, instead it shows the first paragraph of an article.

Here is the Javascript part I am using in the default.html:

      <script type="text/javascript">
      SimpleJekyllSearch.init({
      searchInput: document.getElementById('search-input'),
      resultsContainer: document.getElementById('results-container'),
      dataSource: '/search.json',
      searchResultTemplate: '<a href="{url}" title="{desc}"><div class="search-result"><h3>{title}<\/h3><div class="search-result-text">{desc}<\/div><\/div><\/a>',
      noResultsText: 'No results found',
      limit: 10,
      fuzzy: true,
      })
      </script>

And here is the front matter and first paragraph of the article:

---

date: 2017-01-16

title: Azure

categories:

- deployment

description: "Deploy your Jekyll site to Azure"

type: Document

---

Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through a converter (like Markdown) and our Liquid renderer, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server.

If you already have a full Ruby development environment with all headers and RubyGems installed, you can create a new Jekyll site by doing the following:

I hope you guys can help me out why the search isnt showing the description.

Thanks!

From the tutorial above the, in the search.json template there is this line:

"desc"     : "{{ post.excerpt | markdownify | strip_html | strip_newlines | escape_once }}"

What it’s doing is taking a post’s excerpt, applying some filters to remove HTML and such and assigns it {desc} which the script above is using as your search text.

Jekyll automatically creates excerpts for you taking the first paragraph of text from a post’s body content. What you can do is define that yourself with YAML Front Matter, something like:

excerpt: "Your custom excerpt text here."

Seeing as you’re doing that, but with the description variable you could rename it… which may break other things in your theme so you’ll need find/replace anywhere that’s used.

Or you can use YAML reference/anchors like this to keep things DRY so you don’t have to repeat the text in front matter.

description: &excerpt "Deploy your Jekyll site to Azure"
excerpt: *excerpt

Or you could just repeat the text

description: "Deploy your Jekyll site to Azure"
excerpt: "Deploy your Jekyll site to Azure"
1 Like

You are my hero!

Thank you very much!!!