diff --git a/app/property/[id]/page.js b/app/property/[id]/page.js index 22bfbe4..2366bec 100644 --- a/app/property/[id]/page.js +++ b/app/property/[id]/page.js @@ -205,6 +205,51 @@ export default function PropertyDetailsPage() { }); }, [property, params.id]); + // Set Open Graph meta tags dynamically for Facebook/Twitter sharing + useEffect(() => { + if (!property) return; + + const typeLabel = property.type === 'villa' ? 'فيلا' : property.type === 'apartment' ? 'شقة' : 'بيت'; + const priceLabel = `${formatCurrency(property.price)} / ${property.priceUnit === 'daily' ? 'يوم' : 'شهر'}`; + const desc = `${typeLabel} في ${property.location?.address || ''} · ${property.bedrooms} غرف نوم · ${property.bathrooms} حمامات · ${property.area} م²`; + const imageUrl = property.images?.[0] + ? (property.images[0].startsWith('http') ? property.images[0] : `http://45.93.137.91${property.images[0]}`) + : ''; + + const setMeta = (prop, content) => { + let tag = document.querySelector(`meta[property="${prop}"]`); + if (!tag) { + tag = document.createElement('meta'); + tag.setAttribute('property', prop); + document.head.appendChild(tag); + } + tag.setAttribute('content', content); + }; + + const setMetaName = (name, content) => { + let tag = document.querySelector(`meta[name="${name}"]`); + if (!tag) { + tag = document.createElement('meta'); + tag.setAttribute('name', name); + document.head.appendChild(tag); + } + tag.setAttribute('content', content); + }; + + setMeta('og:title', `${property.title} - ${priceLabel}`); + setMeta('og:description', desc); + if (imageUrl) setMeta('og:image', imageUrl); + setMeta('og:url', window.location.href); + setMeta('og:type', 'website'); + setMeta('og:site_name', 'SweetHome'); + + // Twitter cards + setMetaName('twitter:card', 'summary_large_image'); + setMetaName('twitter:title', `${property.title} - ${priceLabel}`); + setMetaName('twitter:description', desc); + if (imageUrl) setMetaName('twitter:image', imageUrl); + }, [property]); + const formatCurrency = (amount) => { return amount?.toLocaleString() + ' ل.س'; }; @@ -351,9 +396,18 @@ export default function PropertyDetailsPage() {