Nuxt V3 Content Generate Algolia Index Json

Create server/routes/algolia.json.ts

import { serverQueryContent } from '#content/server'export default defineEventHandler(async (event) => {  // get content/tutorials  const docs = await serverQueryContent(event, '/tutorials').find()  // filter away _index file  return docs.filter(doc => !doc._path.endsWith("/_index")).map(doc => {    return {      objectID: doc._id,      date: doc.date,      lastmod: doc.lastmod || doc.date,      title: doc.title,      description: doc.description,      tags: doc.tags,      path: doc._path    }  })})

You can generate the json file via http://localhost:3000/algolia.json

If you generate static website, edit nuxt.config.ts

export default defineNuxtConfig({  nitro: {    prerender: {      routes: ['/algolia.json'],    }  }})

dist/algolia.json shall be generated after you run npm run generate

NOTE: If you prefer create index via Algolia API, try algolia/nuxt.

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.