Function: generateProductRssFeed
product-rss-feedproduct-rss-feed.generateProductRssFeed
▸ generateProductRssFeed(rawProducts, options?): Promise<string>
generateProductRssFeed generates a RSS feed for your products. It can write the feed to a file if you specify a path. It will also validate your products against the productRssFeedItemSchemaproductRssFeedItemSchema for any validation issues.
z.ZodError if there are any validation issues. You can find the issues by looking a the exceptions issues property to determine the exact issues. This only happens if `options.strict = true'.
Minimal example with a single product that writes to the public directory in Next.js.
import { generateProductRssFeed } from '@chordcommerce/product-rss-feed/dist/simple'
import path from 'node:path'
async function main() {
const product = {
id: 'product-1',
title: 'Product 1',
description: 'Lorem ipsum',
availability: 'in_stock',
image_link: 'https://example.com/product-1.jpg',
price: '10 USD',
gtin: '00000000',
}
await generateProductRssFeed([product], {
title: 'Plant Store',
description: 'The best plants in the world',
url: 'https://example.com',
strict: true,
path: path.join(process.cwd(), 'public', 'products.rss'),
})
}
main()Parameters
Name | Type |
|---|---|
rawProducts | ProductFeedItemInputProductFeedItemInput[] |
options? | ProductFeedOptionsProductFeedOptions |
Returns
Promise<string>
The RSS feed as a string.