DEV Community

Mark Sta Ana
Mark Sta Ana

Posted on • Originally published at on

Adding search to your cobalt site - Part Two

This will be a two part post, where I detail the steps it took to enable search on my Cobalt site.

As you may have gathered in part one creating manual document collections is a bit of a chore, and can be easily done using the liquid templating engine.


front matter

title: lunr index
path: /js/lunr_docs.json
Enter fullscreen mode Exit fullscreen mode

The item of note here, is the path which Cobalt will use to create the lunr document collection.


{% assign idx = 0 %}
{% assign post_count = posts | size %}
    }{% if idx < post_count %},{% endif %}
        "content" : "{{ post.content | strip_html | strip_newlines 
                                     | replace: "\", "\\" }}"
        "href" : "{{ post.permalink }}",
        "title" : "{{ post.title }}",
{% endfor %}
Enter fullscreen mode Exit fullscreen mode

The only real difference here between a blog index is that I'm tracking the last post using an index so I can omit a trailing comma.

Don't forget to remove the manually generated document collection (lunr_docs.json) from the assets directory for javascript files (js/) , as this caught me out and made me wonder why the index wasn't being updated.


2017-06-21 - Change references to the lunr index to the lunr document collection.

Top comments (1)

Sloan, the sloth mascot
Comment deleted