techveda-lib-seo
Version:
SEO management package for React or JavaScript frameworks
26 lines (25 loc) • 2.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_helmet_1 = require("react-helmet");
const react_router_dom_1 = require("react-router-dom");
const Seo = ({ domainUrl, name = "Your App Name", title = "Default Title", description = "Default description for your application.", image, robots = "index,follow", type = "website", socialMediaLinks, twitterHandle = "@yourTwitterHandle", }) => {
const location = (0, react_router_dom_1.useLocation)();
const domain = domainUrl || (typeof window !== "undefined" ? window.location.hostname : "localhost");
;
const canonical = `https://${domain}${location.pathname}`;
const structuredData = {
"@context": "https://schema.org",
"@type": "Organization",
name: name,
url: `https://${domain}`,
logo: `https://${domain}/logo192.png`,
sameAs: socialMediaLinks || [
`https://www.facebook.com/${name.replace(/\s+/g, "")}`,
`https://twitter.com/${name.replace(/\s+/g, "")}`,
`https://www.linkedin.com/company/${name.replace(/\s+/g, "")}`
]
};
return ((0, jsx_runtime_1.jsxs)(react_helmet_1.Helmet, { children: [(0, jsx_runtime_1.jsx)("title", { children: title }), (0, jsx_runtime_1.jsx)("meta", { name: "description", content: description }), (0, jsx_runtime_1.jsx)("meta", { name: "robots", content: robots }), (0, jsx_runtime_1.jsx)("link", { rel: "canonical", href: canonical }), (0, jsx_runtime_1.jsx)("meta", { property: "og:site_name", content: name }), (0, jsx_runtime_1.jsx)("meta", { property: "og:locale", content: "en_US" }), (0, jsx_runtime_1.jsx)("meta", { property: "og:title", content: title }), (0, jsx_runtime_1.jsx)("meta", { property: "og:description", content: description }), (0, jsx_runtime_1.jsx)("meta", { property: "og:type", content: type }), (0, jsx_runtime_1.jsx)("meta", { property: "og:url", content: canonical }), (0, jsx_runtime_1.jsx)("meta", { property: "og:image", content: image || `https://${domain}/social-preview.jpg` }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:card", content: "summary_large_image" }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:title", content: title }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:description", content: description }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:image", content: image || `https://${domain}/social-preview.jpg` }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:site", content: twitterHandle }), (0, jsx_runtime_1.jsx)("meta", { name: "twitter:creator", content: twitterHandle }), (0, jsx_runtime_1.jsx)("script", { type: "application/ld+json", children: JSON.stringify(structuredData) })] }));
};
exports.default = Seo;