Use CSV files as data sources in Astro.
npx astro add astro-csv
npm i astro-csv
// astro.config.mjs
import { defineConfig } from 'astro/config'
import astroCSV from 'astro-csv'
export default defineConfig({
integrations: [
astroCSV()
]
})
import { defineCollection, z } from 'astro:content';
const sheets = defineCollection({
type: 'data',
schema: z.object({
rows: z.array(z.array(z.string().or(z.number().or(z.boolean()).nullish()))),
})
});
export const collections = { sheets };
import { defineCollection, z } from 'astro:content';
const sheets = defineCollection({
type: 'data',
schema: z.object({
rows: z.array(z.tuple([
z.string(), // name
z.string(), // email
z.number(), // age
]))
})
});
export const collections = { sheets };