Step 2: Create a Script to Index Posts
Here's a Node.js script that will read your Jekyll posts and populate the search index:
// index-posts.js
const fs = require('fs');
const path = require('path');
const { createClient } = require('@supabase/supabase-js');
const supabaseUrl = 'https://zseqmxgvusdlsllbanzi.supabase.co';
const supabaseKey = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InpzZXFteGd2dXNkbHNsbGJhbnppIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTkzMzMzNzcsImV4cCI6MjA3NDkwOTM3N30.xqnuGg59uno4XYjQO3k6nwrF24ozuK1p-krJVVE_0Qc';
const supabase = createClient(supabaseUrl, supabaseKey);
const postsDir = path.join(__dirname, '_posts');
async function indexPosts() {
const files = fs.readdirSync(postsDir);
for (const file of files) {
if (!file.endsWith('.html') && !file.endsWith('.md')) continue;
const filePath = path.join(postsDir, file);
const content = fs.readFileSync(filePath, 'utf-8');
const titleMatch = content.match(/title:\s*['"](.+?)['"]/);
const categoriesMatch = content.match(/categories:\s*\n([\s\S]*?)(?=\n[a-z_]+:|---)/);
const permalinkMatch = content.match(/permalink:\s*["'](.+?)["']/);
if (!titleMatch || !permalinkMatch) continue;
const title = titleMatch[1];
const permalink = permalinkMatch[1].replace(/^\/|\/$/g, '');
let categories = '';
if (categoriesMatch) {
categories = categoriesMatch[1]
.split('\n')
.map(line => line.replace(/^-\s*/, '').trim())
.filter(Boolean)
.join(', ');
}
const textContent = content
.replace(/---[\s\S]*?---/, '')
.replace(/<[^>]*>/g, ' ')
.replace(/\s+/g, ' ')
.trim()
.substring(0, 5000);
const { error } = await supabase
.from('search_index')
.upsert({
post_slug: permalink,
title: title,
content: textContent,
categories: categories
}, {
onConflict: 'post_slug'
});
if (error) {
console.error(`Error indexing ${file}:`, error);
} else {
console.log(`Indexed: ${title}`);
}
}
console.log('Indexing complete!');
}
indexPosts();
Step 3: Run the Script
Save the script as index-posts.js in your project root and run:
npm install @supabase/supabase-js
node index-posts.js
Note About Jekyll Build
Your Jekyll site uses custom layouts and styles that override the Minima theme. To build and preview locally, you'll need:
- Ruby installed on your system
- Run:
gem install bundler jekyll
- Run:
bundle install
- Run:
bundle exec jekyll serve
The site will be available at http://localhost:4000