Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/notrab/stripe-astro-loader
Fetch data from the Stripe API and use it in Astro collections
https://github.com/notrab/stripe-astro-loader
astro astro-integration stripe
Last synced: 3 months ago
JSON representation
Fetch data from the Stripe API and use it in Astro collections
- Host: GitHub
- URL: https://github.com/notrab/stripe-astro-loader
- Owner: notrab
- Created: 2024-08-15T20:08:05.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-09-22T14:11:29.000Z (4 months ago)
- Last Synced: 2024-09-27T21:24:16.244Z (4 months ago)
- Topics: astro, astro-integration, stripe
- Language: TypeScript
- Homepage:
- Size: 230 KB
- Stars: 26
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# stripe-astro-loader
Fetch data from the Stripe API and use it in Astro collections — only has **products** for now.
## Install
```bash
npm i stripe stripe-astro-loader
```## Configure
```ts
import { defineCollection } from "astro:content";
import { stripeProductLoader } from "stripe-astro-loader";
import Stripe from "stripe";const stripe = new Stripe("SECRET_KEY");
const products = defineCollection({
loader: stripeProductLoader(stripe),
});const prices = defineCollection({
loader: stripePriceLoader(stripe),
});export const collections = { products, prices };
```Make sure to enable the experimental content layer in your Astro config:
```ts
import { defineConfig } from "astro/config";export default defineConfig({
experimental: {
contentLayer: true,
},
});
```## Usage
```astro
// pages/index.astro
---
import { getCollection } from 'astro:content';const products = await getCollection('products');
---
``````astro
// pages/products/[id].astro
---
import { getCollection,render } from 'astro:content';export async function getStaticPaths() {
const products = await getCollection('products');return products.map(product => ({
params: { id: product.id }, props: { product },
}));
}const { product } = Astro.props;
const { Content, headings } = await render(product);
---{product.data.name}
{JSON.stringify({product, headings}, null, 2)}```