DEV Community

Mark Sta Ana
Mark Sta Ana

Posted on • Originally published at booyaa.wtf on

2 2

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.

lunr.liquid

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.

content

[
{% 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.

Updates

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (1)

Collapse
 
Sloan, the sloth mascot
Comment deleted

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay