Explore More Passive Income Ideas

add search to jekyll without javascript frameworks

Why Use Native Search for Jekyll Most Jekyll blogs rely on static content, which makes traditional database-driven search impossible. However, you don’t need heavy JavaScript frameworks like Vue or React to implement search. By leveraging JSON, Liquid, and a bit of vanilla JavaScript, you can create a responsive search experience that works on any static host—even GitHub Pages. Core Concepts Here’s the approach we’ll take: Generate a JSON index of your posts during build time Load the JSON file with plain JavaScript Match user input against title and content Display matching posts as results dynamically Step 1: Create a Search Index in JSON Add a new file called search.json at the root of your project: --- layout: null --- [ {% raw %}{% for post in site.posts %} { "title": "{{ post.title | escape }}", "url": "{{ post.url | absolute_url }}", "date": "{{ post.date | date: '%Y-%m-%d' }}...

organizing content with tags and categories in jekyll

Why Tags and Categories Matter in Static Blogs

Unlike dynamic CMS platforms, Jekyll doesn’t automatically create tag or category archives. But organizing your content with proper taxonomies is still critical. It helps readers explore related posts and improves your internal linking structure for SEO.

Categories vs Tags in Jekyll

Though they serve similar purposes, tags and categories are conceptually different:

  • Categories: Broad, hierarchical groupings (e.g., tutorials, case-studies, tips)
  • Tags: Specific keywords describing content details (e.g., jekyll-seo, liquid, layouts)

Each post can have multiple tags and categories. Here’s how to implement them properly.

Step 1: Add Tags and Categories to Front Matter

In each markdown or HTML post, define tags and categories like this:

---
title: "your post title"
categories: [jekyll, seo]
tags: [jekyll-seo, meta-tags, optimization]
---

Use lowercase and hyphen-separated words for better consistency and URL structure.

Step 2: Create a Tags and Categories Layout

Jekyll doesn’t generate these pages by default. You must create custom layouts. First, define a tag.html and category.html template in your _layouts folder.

Sample tag.html:

<h2>Posts tagged with "{{ page.tag }}"</h2>
<ul>
  {% for post in site.tags[page.tag] %}
    <li>
      <a href="{{ post.url }}">{{ post.title }}</a>
    </li>
  {% endfor %}
</ul>

Sample category.html:

<h2>Posts in category "{{ page.category }}"</h2>
<ul>
  {% for post in site.categories[page.category] %}
    <li>
      <a href="{{ post.url }}">{{ post.title }}</a>
    </li>
  {% endfor %}
</ul>

Step 3: Build Pages for Each Tag and Category

Inside a tags and categories folder, create individual files for each tag and category. Example for the tag jekyll-seo:

/tags/jekyll-seo.md
---
layout: tag
tag: jekyll-seo
permalink: /tags/jekyll-seo/
---

Repeat for each category with the category layout.

Step 4: Automate with a Generator Script (Optional)

If your blog has dozens of tags and categories, automating the archive page generation makes maintenance easier. You can write a Ruby or shell script to loop through all site.tags and site.categories and create the appropriate markdown files.

Step 5: Link Tags and Categories in Your Post Layout

Update your post layout (e.g., _layouts/post.html) to show tag and category links:

<p>Categories: 
  {% for category in page.categories %}
    <a href="/categories/{{ category }}/">{{ category }}</a> 
  {% endfor %}
</p>

<p>Tags: 
  {% for tag in page.tags %}
    <a href="/tags/{{ tag }}/">{{ tag }}</a> 
  {% endfor %}
</p>

Step 6: Style Your Archives

Apply CSS to your tag/category archive pages to make them visually distinct. Consider grouping related tags visually or using a tag cloud. Use CSS classes for each tag if needed:

.tag-cloud a {
  font-size: 1.2em;
  margin-right: 10px;
  color: #337ab7;
}

Step 7: Use Tags and Categories for Internal Linking

Encourage readers to explore related content by linking tags and categories within post bodies. This keeps users on your site longer and strengthens topical authority in the eyes of search engines.

Conclusion

Tagging and categorization in Jekyll may take extra effort compared to CMS platforms, but the reward is a highly organized, navigable site with improved SEO. With thoughtful implementation, your blog becomes easier to explore for readers and bots alike. Don't neglect this foundation—it's one of the simplest ways to future-proof your static content structure.


Archives / All Content


© ScrollBuzzLab . All rights reserved.