techveda-react-seo
Version:
Complete React SEO automation library with meta tags, robots.txt and sitemap generation
41 lines • 3.24 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { Helmet } from 'react-helmet';
import { useLocation } from 'react-router-dom';
export var Seo = function (_a) {
var domainUrl = _a.domainUrl, _b = _a.name, name = _b === void 0 ? 'Your App Name' : _b, _c = _a.title, title = _c === void 0 ? 'Default Title' : _c, _d = _a.description, description = _d === void 0 ? 'Default description for your application.' : _d, image = _a.image, _e = _a.robots, robots = _e === void 0 ? 'index,follow' : _e, _f = _a.type, type = _f === void 0 ? 'website' : _f, socialMediaLinks = _a.socialMediaLinks, _g = _a.twitterHandle, twitterHandle = _g === void 0 ? '@yourTwitterHandle' : _g, sitemap = _a.sitemap;
var location = useLocation();
var _h = useState(location.pathname), currentPath = _h[0], setCurrentPath = _h[1];
useEffect(function () {
// Update on route change
setCurrentPath(location.pathname);
}, [location.pathname]);
var domain = domainUrl ||
(typeof window !== 'undefined' ? window.location.hostname : 'localhost');
var canonical = "https://".concat(domain).concat(currentPath);
var structuredData = {
'@context': 'https://schema.org',
'@type': 'Organization',
name: name,
url: "https://".concat(domain),
logo: "https://".concat(domain, "/logo192.png"),
sameAs: socialMediaLinks || [
"https://www.facebook.com/".concat(name.replace(/\s+/g, '')),
"https://twitter.com/".concat(name.replace(/\s+/g, '')),
"https://www.linkedin.com/company/".concat(name.replace(/\s+/g, '')),
],
};
return (_jsxs(Helmet, { children: [_jsx("title", { children: title }), _jsx("meta", { name: "description", content: description }), _jsx("meta", { name: "robots", content: robots }), _jsx("link", { rel: "canonical", href: canonical }), _jsx("meta", { property: "og:title", content: title }), _jsx("meta", { property: "og:description", content: description }), _jsx("meta", { property: "og:type", content: type }), _jsx("meta", { property: "og:url", content: canonical }), _jsx("meta", { property: "og:image", content: image || "https://".concat(domain, "/social-preview.jpg") }), _jsx("meta", { name: "twitter:card", content: "summary_large_image" }), _jsx("meta", { name: "twitter:title", content: title }), _jsx("meta", { name: "twitter:description", content: description }), _jsx("meta", { name: "twitter:image", content: image || "https://".concat(domain, "/social-preview.jpg") }), _jsx("meta", { name: "twitter:site", content: twitterHandle }), _jsx("meta", { name: "twitter:creator", content: twitterHandle }), _jsx("script", __assign({ type: "application/ld+json" }, { children: JSON.stringify(structuredData) }))] }));
};
//# sourceMappingURL=Seo.js.map