@umituz/web-seo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import React from "react";
2
+ import { SEOptions } from "../utils/dom.js";
3
+ export declare const SEO: React.FC<SEOptions>;
4
+ //# sourceMappingURL=SEO.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SEO.d.ts","sourceRoot":"","sources":["../../src/components/SEO.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAa,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEvD,eAAO,MAAM,GAAG,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAcnC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { useEffect } from "react";
2
+ import { updateSEO } from "../utils/dom.js";
3
+ export const SEO = (props) => {
4
+ useEffect(() => {
5
+ updateSEO(props);
6
+ }, [
7
+ props.title,
8
+ props.description,
9
+ props.lang,
10
+ props.canonical,
11
+ JSON.stringify(props.meta),
12
+ JSON.stringify(props.openGraph),
13
+ JSON.stringify(props.twitter),
14
+ ]);
15
+ return null; // Component does not render anything
16
+ };
@@ -0,0 +1,3 @@
1
+ import { SEOptions } from "../utils/dom.js";
2
+ export declare const useSEO: (options: SEOptions) => void;
3
+ //# sourceMappingURL=useSEO.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useSEO.d.ts","sourceRoot":"","sources":["../../src/hooks/useSEO.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEvD,eAAO,MAAM,MAAM,GAAI,SAAS,SAAS,SAYxC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { useEffect } from "react";
2
+ import { updateSEO } from "../utils/dom.js";
3
+ export const useSEO = (options) => {
4
+ useEffect(() => {
5
+ updateSEO(options);
6
+ }, [
7
+ options.title,
8
+ options.description,
9
+ options.lang,
10
+ options.canonical,
11
+ JSON.stringify(options.meta),
12
+ JSON.stringify(options.openGraph),
13
+ JSON.stringify(options.twitter),
14
+ ]);
15
+ };
@@ -0,0 +1,5 @@
1
+ export { SEO } from "./components/SEO.js";
2
+ export { useSEO } from "./hooks/useSEO.js";
3
+ export { updateSEO } from "./utils/dom.js";
4
+ export type { SEOptions, MetaTag } from "./utils/dom.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { SEO } from "./components/SEO.js";
2
+ export { useSEO } from "./hooks/useSEO.js";
3
+ export { updateSEO } from "./utils/dom.js";
@@ -0,0 +1,26 @@
1
+ export interface MetaTag {
2
+ name?: string;
3
+ property?: string;
4
+ content: string;
5
+ }
6
+ export interface SEOptions {
7
+ title?: string;
8
+ description?: string;
9
+ lang?: string;
10
+ canonical?: string;
11
+ meta?: MetaTag[];
12
+ openGraph?: {
13
+ type?: string;
14
+ url?: string;
15
+ title?: string;
16
+ description?: string;
17
+ image?: string;
18
+ };
19
+ twitter?: {
20
+ cardType?: string;
21
+ site?: string;
22
+ handle?: string;
23
+ };
24
+ }
25
+ export declare const updateSEO: (options: SEOptions) => void;
26
+ //# sourceMappingURL=dom.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/utils/dom.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,SAAS;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,SAAS,CAAC,EAAE;QACV,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,CAAC,EAAE;QACR,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;CACH;AAcD,eAAO,MAAM,SAAS,GAAI,SAAS,SAAS,SAuD3C,CAAC"}
@@ -0,0 +1,74 @@
1
+ const setMetaTag = (attrName, attrValue, content) => {
2
+ if (typeof document === "undefined")
3
+ return;
4
+ let element = document.querySelector(`meta[${attrName}="${attrValue}"]`);
5
+ if (!element) {
6
+ element = document.createElement("meta");
7
+ element.setAttribute(attrName, attrValue);
8
+ document.head.appendChild(element);
9
+ }
10
+ element.setAttribute("content", content);
11
+ };
12
+ export const updateSEO = (options) => {
13
+ if (typeof document === "undefined")
14
+ return;
15
+ // Title
16
+ if (options.title) {
17
+ document.title = options.title;
18
+ }
19
+ // Language
20
+ if (options.lang) {
21
+ document.documentElement.lang = options.lang;
22
+ }
23
+ // Description
24
+ if (options.description) {
25
+ setMetaTag("name", "description", options.description);
26
+ }
27
+ // Canonical
28
+ if (options.canonical) {
29
+ let link = document.querySelector('link[rel="canonical"]');
30
+ if (!link) {
31
+ link = document.createElement("link");
32
+ link.setAttribute("rel", "canonical");
33
+ document.head.appendChild(link);
34
+ }
35
+ link.setAttribute("href", options.canonical);
36
+ }
37
+ // Custom Meta
38
+ if (options.meta && Array.isArray(options.meta)) {
39
+ options.meta.forEach(m => {
40
+ if (m.name)
41
+ setMetaTag("name", m.name, m.content);
42
+ if (m.property)
43
+ setMetaTag("property", m.property, m.content);
44
+ });
45
+ }
46
+ // Open Graph
47
+ if (options.openGraph) {
48
+ if (options.openGraph.title)
49
+ setMetaTag("property", "og:title", options.openGraph.title);
50
+ if (options.openGraph.description)
51
+ setMetaTag("property", "og:description", options.openGraph.description);
52
+ if (options.openGraph.url)
53
+ setMetaTag("property", "og:url", options.openGraph.url);
54
+ if (options.openGraph.type)
55
+ setMetaTag("property", "og:type", options.openGraph.type);
56
+ if (options.openGraph.image)
57
+ setMetaTag("property", "og:image", options.openGraph.image);
58
+ }
59
+ // Twitter
60
+ if (options.twitter) {
61
+ if (options.twitter.cardType)
62
+ setMetaTag("name", "twitter:card", options.twitter.cardType);
63
+ if (options.twitter.site)
64
+ setMetaTag("name", "twitter:site", options.twitter.site);
65
+ if (options.twitter.handle)
66
+ setMetaTag("name", "twitter:creator", options.twitter.handle);
67
+ if (options.description)
68
+ setMetaTag("name", "twitter:description", options.description);
69
+ if (options.title)
70
+ setMetaTag("name", "twitter:title", options.title);
71
+ if (options.openGraph?.image)
72
+ setMetaTag("name", "twitter:image", options.openGraph.image);
73
+ }
74
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@umituz/web-seo",
3
+ "version": "1.0.0",
4
+ "description": "Dynamic SEO and meta tag manager for React web applications",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "lint": "eslint .",
11
+ "typecheck": "tsc --noEmit"
12
+ },
13
+ "exports": {
14
+ ".": "./dist/index.js",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md"
20
+ ],
21
+ "author": "umituz",
22
+ "license": "MIT",
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "peerDependencies": {
27
+ "react": ">=16.8.0",
28
+ "react-dom": ">=16.8.0"
29
+ },
30
+ "devDependencies": {
31
+ "@types/react": "^18.3.2",
32
+ "@types/react-dom": "^18.3.0",
33
+ "eslint": "^8.57.0",
34
+ "typescript": "^5.4.5"
35
+ }
36
+ }