@umituz/web-seo 2.3.1 → 2.4.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.
@@ -21,6 +21,32 @@ const upsertMetaTag = (html, attributeName, attributeValue, content) => {
21
21
  const newTag = `<meta ${attributeName}="${attributeValue}" content="${escapeHtml(content)}" />`;
22
22
  return upsertTag(html, regex, newTag);
23
23
  };
24
+ const replaceRootContent = (html, newContent) => {
25
+ const rootMatch = html.match(/<div\s+[^>]*?id=["']root["'][^>]*>/i);
26
+ if (!rootMatch || rootMatch.index === undefined)
27
+ return html;
28
+ const startIdx = rootMatch.index + rootMatch[0].length;
29
+ let depth = 1;
30
+ let pos = startIdx;
31
+ while (pos < html.length && depth > 0) {
32
+ const nextOpen = html.indexOf("<div", pos);
33
+ const nextClose = html.indexOf("</div>", pos);
34
+ if (nextClose === -1)
35
+ break;
36
+ if (nextOpen !== -1 && nextOpen < nextClose) {
37
+ depth++;
38
+ pos = nextOpen + 4;
39
+ }
40
+ else {
41
+ depth--;
42
+ if (depth === 0) {
43
+ return `${html.slice(0, startIdx)}\n${newContent}\n ${html.slice(nextClose)}`;
44
+ }
45
+ pos = nextClose + 6;
46
+ }
47
+ }
48
+ return html;
49
+ };
24
50
  export const injectRouteMeta = (htmlTemplate, meta, siteUrl, routePath) => {
25
51
  let html = htmlTemplate;
26
52
  const normalizedSiteUrl = siteUrl.replace(/\/$/, "");
@@ -105,5 +131,8 @@ export const injectRouteMeta = (htmlTemplate, meta, siteUrl, routePath) => {
105
131
  const existingJsonLdRegex = /<script\s+[^>]*?type=["']application\/ld\+json["'][^>]*>[\s\S]*?<\/script>/i;
106
132
  html = upsertTag(html, existingJsonLdRegex, jsonLdTag);
107
133
  }
134
+ if (meta.bodyHtml) {
135
+ html = replaceRootContent(html, meta.bodyHtml);
136
+ }
108
137
  return html;
109
138
  };
@@ -29,6 +29,7 @@ export interface RouteMeta {
29
29
  creator?: string;
30
30
  };
31
31
  jsonLd?: Record<string, unknown> | Array<Record<string, unknown>>;
32
+ bodyHtml?: string;
32
33
  }
33
34
  export interface PrerenderOptions {
34
35
  routes?: Record<string, RouteMeta>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-seo",
3
- "version": "2.3.1",
3
+ "version": "2.4.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",