@umituz/web-seo 2.1.1 → 2.2.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.
@@ -590,7 +590,10 @@ export const twitterStrategy = {
590
590
  export const jsonLdStrategy = {
591
591
  id: "json-ld",
592
592
  applies: (o) => Boolean(o.jsonLd && o.jsonLd.length > 0),
593
- applyDOM: () => {
593
+ applyDOM: (o, ctx) => {
594
+ if (!o.jsonLd)
595
+ return;
596
+ ctx.setJsonLd(o.jsonLd);
594
597
  },
595
598
  applyHTML: (o, ctx) => {
596
599
  if (!o.jsonLd)
@@ -2,6 +2,7 @@ import type { SEOptions } from "../types/index.js";
2
2
  export interface DOMContext {
3
3
  setMeta: (name: string, content: string | undefined) => void;
4
4
  setLink: (attrs: Record<string, string>) => void;
5
+ setJsonLd: (data: unknown[]) => void;
5
6
  }
6
7
  export interface HTMLContext {
7
8
  meta: string[];
@@ -44,5 +44,19 @@ export const createDOMContext = () => {
44
44
  element.setAttribute(key, value);
45
45
  }
46
46
  };
47
- return { setMeta, setLink };
47
+ const setJsonLd = (data) => {
48
+ if (typeof document === "undefined")
49
+ return;
50
+ document
51
+ .querySelectorAll('script[type="application/ld+json"][data-seo="true"]')
52
+ .forEach((el) => el.remove());
53
+ for (const item of data) {
54
+ const script = document.createElement("script");
55
+ script.type = "application/ld+json";
56
+ script.setAttribute("data-seo", "true");
57
+ script.textContent = JSON.stringify(item);
58
+ document.head.appendChild(script);
59
+ }
60
+ };
61
+ return { setMeta, setLink, setJsonLd };
48
62
  };
@@ -23,6 +23,7 @@ export const clearSEO = () => {
23
23
  return;
24
24
  document.querySelectorAll('meta[data-seo="true"]').forEach((el) => el.remove());
25
25
  document.querySelectorAll('link[data-seo="true"]').forEach((el) => el.remove());
26
+ document.querySelectorAll('script[type="application/ld+json"][data-seo="true"]').forEach((el) => el.remove());
26
27
  document.title = "";
27
28
  };
28
29
  export const getCurrentSEOState = () => {
@@ -1,3 +1,3 @@
1
1
  export { viteSEOPlugin } from "./plugin.js";
2
2
  export { quickSEOSetup } from "./presets.js";
3
- export type { ViteSEOPluginOptions } from "./types.js";
3
+ export type { ViteSEOPluginOptions, SitemapRouteItem, SitemapChangeFreq } from "./types.js";
@@ -16,19 +16,33 @@ export const viteSEOPlugin = (options) => {
16
16
  },
17
17
  generateBundle() {
18
18
  const outDir = pluginState.outDir ?? "dist";
19
- let routes = [...manualRoutes];
19
+ const routes = [...manualRoutes];
20
20
  if (discoverRoutes) {
21
21
  const discovered = discoverRoutesFromBuild(outDir);
22
- routes = Array.from(new Set([...routes, ...discovered]));
22
+ for (const item of discovered) {
23
+ const alreadyExists = routes.some((r) => (typeof r === "string" ? r === item : r.url === item));
24
+ if (!alreadyExists)
25
+ routes.push(item);
26
+ }
23
27
  }
24
28
  if (routes.length === 0)
25
29
  routes.push("/");
26
- const sitemapUrls = routes.map((route) => ({
27
- loc: `${normalizedSiteUrl}${route}`,
28
- lastmod: sitemapOptions.lastmod,
29
- changefreq: sitemapOptions.changefreq,
30
- priority: sitemapOptions.priority,
31
- }));
30
+ const sitemapUrls = routes.map((entry) => {
31
+ if (typeof entry === "string") {
32
+ return {
33
+ loc: `${normalizedSiteUrl}${entry}`,
34
+ lastmod: sitemapOptions.lastmod,
35
+ changefreq: sitemapOptions.changefreq,
36
+ priority: sitemapOptions.priority,
37
+ };
38
+ }
39
+ return {
40
+ loc: `${normalizedSiteUrl}${entry.url}`,
41
+ lastmod: entry.lastmod ?? sitemapOptions.lastmod,
42
+ changefreq: entry.changefreq ?? sitemapOptions.changefreq,
43
+ priority: entry.priority ?? sitemapOptions.priority,
44
+ };
45
+ });
32
46
  this.emitFile({
33
47
  type: "asset",
34
48
  fileName: sitemapFilename,
@@ -1,10 +1,17 @@
1
+ export type SitemapChangeFreq = "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
2
+ export interface SitemapRouteItem {
3
+ url: string;
4
+ priority?: number;
5
+ changefreq?: SitemapChangeFreq;
6
+ lastmod?: string;
7
+ }
1
8
  export interface ViteSEOPluginOptions {
2
9
  siteUrl: string;
3
- routes?: string[];
10
+ routes?: Array<string | SitemapRouteItem>;
4
11
  discoverRoutes?: boolean;
5
12
  sitemap?: {
6
13
  filename?: string;
7
- changefreq?: "always" | "hourly" | "daily" | "weekly" | "monthly" | "yearly" | "never";
14
+ changefreq?: SitemapChangeFreq;
8
15
  priority?: number;
9
16
  lastmod?: string;
10
17
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-seo",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "Comprehensive SEO solution for React Vite applications with structured data, performance hints, and build-time optimization",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",