Hi.
I have a content collection defined in src/content.config.ts like this:
import { defineCollection } from 'astro/content/config';
import { glob } from 'astro/loaders';
import { z } from 'astro/zod';
const appSchema = z.object({ name: z.string() });
const apps = defineCollection({
loader: glob({
base: './src/content/apps',
pattern: '**/*.md',
}),
schema: appSchema,
});
export const collections = { apps };
As you can see, it's a collection of markdown files located in src/content/apps, each having specific properties such as name defined in the schema.
Now I want to integrate pagefind, but not in the traditional way where it scans the build output, instead I need to access my collection at build time, then send this data to pagefind API programatically and it will generate it's own files for me.
But the question is, how do I do that? Right now I'm trying to create a custom integration like this:
import type { AstroIntegration } from 'astro';
import { getCollection } from 'astro:content';
function testIntegration(): AstroIntegration {
return {
name: 'pagefind-integration',
hooks: {
'astro:build:done': async ({ assets, dir, logger, pages }) => { const apps = await getCollection('apps');
},
},
};
}
export { testIntegration };
// then in my astro.config.ts
export default defineConfig({
integrations: [testIntegration()],
});
However, I am getting errors because I don't think I'm allowed to use getCollection in integrations, is that correct? How do I tackle this problem.