https://github.com/theotterlord/astro-csv
CSVs for Astro data collections
https://github.com/theotterlord/astro-csv
astro withastro
Last synced: 16 days ago
JSON representation
CSVs for Astro data collections
- Host: GitHub
- URL: https://github.com/theotterlord/astro-csv
- Owner: TheOtterlord
- Created: 2023-05-18T22:20:01.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-08T15:52:40.000Z (over 1 year ago)
- Last Synced: 2025-03-31T12:57:10.357Z (about 1 month ago)
- Topics: astro, withastro
- Language: TypeScript
- Homepage:
- Size: 111 MB
- Stars: 12
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Astro CSV Integration
Use CSV files as data sources in Astro.
## Install
```sh
npx astro add astro-csv
```### Manual install
```sh
npm i astro-csv
``````ts
// astro.config.mjs
import { defineConfig } from 'astro/config'
import astroCSV from 'astro-csv'export default defineConfig({
integrations: [
astroCSV()
]
})
```## Usage
### Accept any data
```ts
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 };
```### Accept typed data
```ts
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 };
```