186 lines
5.5 KiB
TypeScript
186 lines
5.5 KiB
TypeScript
import { Product } from '@/types'
|
|
import {
|
|
Product as SchemaProduct,
|
|
WithContext,
|
|
Organization,
|
|
ContactPoint,
|
|
PostalAddress,
|
|
BreadcrumbList,
|
|
FAQPage,
|
|
LocalBusiness,
|
|
ItemList
|
|
} from 'schema-dts'
|
|
|
|
export function generateProductJsonLd(product: Product, baseUrl: string = ''): WithContext<SchemaProduct> {
|
|
const currentPrice = product.discount
|
|
? product.price - (product.price * product.discount / 100)
|
|
: product.price
|
|
|
|
const productJsonLd: WithContext<SchemaProduct> = {
|
|
"@context": "https://schema.org",
|
|
"@type": "Product",
|
|
"@id": `${baseUrl}/products/${product.slug || product.id}`,
|
|
"name": product.name,
|
|
"description": product.description || `Premium quality ${product.category.name} rice from Padmaaja Rasooi`,
|
|
"image": product.images.map(img => `${baseUrl}${img}`),
|
|
"brand": {
|
|
"@type": "Brand",
|
|
"name": product.brand || "Padmaaja Rasooi"
|
|
},
|
|
"category": product.category.name,
|
|
"sku": product.sku || product.id,
|
|
"offers": {
|
|
"@type": "Offer",
|
|
"url": `${baseUrl}/products/${product.id}`,
|
|
"priceCurrency": "INR",
|
|
"price": currentPrice.toFixed(2),
|
|
"priceValidUntil": new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0],
|
|
"availability": product.stock && product.stock > 0
|
|
? "https://schema.org/InStock"
|
|
: "https://schema.org/OutOfStock",
|
|
"seller": {
|
|
"@type": "Organization",
|
|
"name": "Padmaaja Rasooi",
|
|
"url": baseUrl
|
|
},
|
|
},
|
|
"aggregateRating": {
|
|
"@type": "AggregateRating",
|
|
"ratingValue": "4.8",
|
|
"bestRating": "5",
|
|
"worstRating": "1",
|
|
"ratingCount": "125"
|
|
}
|
|
}
|
|
|
|
return productJsonLd
|
|
}
|
|
|
|
export function generateProductListJsonLd(products: Product[], baseUrl: string = ''): WithContext<ItemList> {
|
|
return {
|
|
"@context": "https://schema.org",
|
|
"@type": "ItemList",
|
|
"name": "Padmaaja Rasooi Premium Rice Products",
|
|
"description": "Complete collection of premium quality rice products",
|
|
"numberOfItems": products.length,
|
|
"itemListElement": products.map((product, index) => ({
|
|
"@type": "ListItem",
|
|
"position": index + 1,
|
|
"item": {
|
|
"@type": "Product",
|
|
"@id": `${baseUrl}/products/${product.slug || product.id}`,
|
|
"name": product.name,
|
|
"image": product.images[0] ? `${baseUrl}${product.images[0]}` : '',
|
|
"offers": {
|
|
"@type": "Offer",
|
|
"priceCurrency": "INR",
|
|
"price": (product.discount
|
|
? product.price - (product.price * product.discount / 100)
|
|
: product.price).toFixed(2)
|
|
}
|
|
}
|
|
}))
|
|
}
|
|
}
|
|
|
|
export function generateOrganizationJsonLd(baseUrl: string = ''): WithContext<Organization> {
|
|
return {
|
|
"@context": "https://schema.org",
|
|
"@type": "Organization",
|
|
"name": "Padmaaja Rasooi",
|
|
"url": baseUrl,
|
|
"logo": `${baseUrl}/images/logo.png`,
|
|
"description": "Premium rice products and quality grains offering the finest quality rice sourced directly from certified farms.",
|
|
"contactPoint": {
|
|
"@type": "ContactPoint",
|
|
"telephone": "+91-9876543210",
|
|
"email": "contact@padmaajarasooi.com",
|
|
"contactType": "Customer Service"
|
|
},
|
|
"address": {
|
|
"@type": "PostalAddress",
|
|
"streetAddress": "123 Rice Market Street",
|
|
"addressLocality": "Hyderabad",
|
|
"addressRegion": "Telangana",
|
|
"postalCode": "500001",
|
|
"addressCountry": "IN"
|
|
},
|
|
"sameAs": [
|
|
"https://www.facebook.com/padmaajarasooi",
|
|
"https://www.instagram.com/padmaajarasooi",
|
|
"https://www.linkedin.com/company/padmaajarasooi"
|
|
],
|
|
"foundingDate": "2020"
|
|
}
|
|
}
|
|
|
|
export function generateBreadcrumbJsonLd(breadcrumbs: Array<{ name: string, url: string }>, baseUrl: string = ''): WithContext<BreadcrumbList> {
|
|
return {
|
|
"@context": "https://schema.org",
|
|
"@type": "BreadcrumbList",
|
|
"itemListElement": breadcrumbs.map((crumb, index) => ({
|
|
"@type": "ListItem",
|
|
"position": index + 1,
|
|
"name": crumb.name,
|
|
"item": `${baseUrl}${crumb.url}`
|
|
}))
|
|
}
|
|
}
|
|
|
|
export function generateFAQJsonLd(faqs: Array<{ question: string, answer: string }>): WithContext<FAQPage> {
|
|
return {
|
|
"@context": "https://schema.org",
|
|
"@type": "FAQPage",
|
|
"mainEntity": faqs.map(faq => ({
|
|
"@type": "Question",
|
|
"name": faq.question,
|
|
"acceptedAnswer": {
|
|
"@type": "Answer",
|
|
"text": faq.answer
|
|
}
|
|
}))
|
|
}
|
|
}
|
|
|
|
export function generateLocalBusinessJsonLd(baseUrl: string = ''): WithContext<LocalBusiness> {
|
|
return {
|
|
"@context": "https://schema.org",
|
|
"@type": "LocalBusiness",
|
|
"name": "Padmaaja Rasooi",
|
|
"image": `${baseUrl}/images/business-photo.jpg`,
|
|
"description": "Premium rice products and quality grains",
|
|
"url": baseUrl,
|
|
"telephone": "+91-9876543210",
|
|
"email": "contact@padmaajarasooi.com",
|
|
"address": {
|
|
"@type": "PostalAddress",
|
|
"streetAddress": "123 Rice Market Street",
|
|
"addressLocality": "Hyderabad",
|
|
"addressRegion": "Telangana",
|
|
"postalCode": "500001",
|
|
"addressCountry": "IN"
|
|
},
|
|
"geo": {
|
|
"@type": "GeoCoordinates",
|
|
"latitude": "17.3850",
|
|
"longitude": "78.4867"
|
|
},
|
|
"openingHoursSpecification": [
|
|
{
|
|
"@type": "OpeningHoursSpecification",
|
|
"dayOfWeek": [
|
|
"Monday",
|
|
"Tuesday",
|
|
"Wednesday",
|
|
"Thursday",
|
|
"Friday",
|
|
"Saturday"
|
|
],
|
|
"opens": "09:00",
|
|
"closes": "18:00"
|
|
}
|
|
],
|
|
"priceRange": "₹₹"
|
|
}
|
|
}
|