-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSEO.tsx
More file actions
65 lines (57 loc) · 1.99 KB
/
Copy pathSEO.tsx
File metadata and controls
65 lines (57 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { useEffect } from 'react';
interface SEOProps {
title?: string;
description?: string;
url?: string;
type?: string;
schemaData?: any;
}
export const SEO: React.FC<SEOProps> = ({
title = "Mail Factory - Trusted Gmail Exchange Platform",
description = "Bangladesh's #1 Trusted Gmail Exchange Platform. Fast payments, multi-tier reward levels, and high referral commissions.",
url = "https://www.mailfectory.top",
type = "website",
schemaData
}) => {
useEffect(() => {
document.title = title;
const setMeta = (name: string, content: string, isProperty = false) => {
const attr = isProperty ? 'property' : 'name';
let element = document.querySelector(`meta[${attr}="${name}"]`);
if (!element) {
element = document.createElement('meta');
element.setAttribute(attr, name);
document.head.appendChild(element);
}
element.setAttribute('content', content);
};
setMeta('description', description);
setMeta('og:title', title, true);
setMeta('og:description', description, true);
setMeta('og:url', url, true);
setMeta('og:type', type, true);
// Canonical link
let canonical = document.querySelector('link[rel="canonical"]');
if (!canonical) {
canonical = document.createElement('link');
canonical.setAttribute('rel', 'canonical');
document.head.appendChild(canonical);
}
canonical.setAttribute('href', url);
// Structured Data (JSON-LD)
if (schemaData) {
let script = document.getElementById('seo-schema');
if (!script) {
script = document.createElement('script');
script.id = 'seo-schema';
script.setAttribute('type', 'application/ld+json');
document.head.appendChild(script);
}
script.textContent = JSON.stringify(schemaData);
}
return () => {
// Cleanup if needed, but for SPA we can leave them and overwrite on next mount
};
}, [title, description, url, type, schemaData]);
return null;
};