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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
Sloan, the sloth mascot
Comment deleted

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay