fimo-react-router 2.10.0 → 2.10.1-staging.2
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.
- package/dist/seo.d.ts +38 -18
- package/dist/seo.js +33 -11
- package/package.json +6 -6
package/dist/seo.d.ts
CHANGED
|
@@ -3,33 +3,43 @@ type FimoSEO = NonNullable<ReturnType<typeof resolveSeoForPath>>;
|
|
|
3
3
|
export declare function getSeoForPath(pathname: string, routeData?: unknown): FimoSEO | undefined;
|
|
4
4
|
export declare function buildMetaForPath(pathname: string, routeData?: unknown): ({
|
|
5
5
|
title: string;
|
|
6
|
-
name?: undefined;
|
|
7
|
-
property?: undefined;
|
|
8
|
-
content?: undefined;
|
|
9
6
|
tagName?: undefined;
|
|
10
7
|
rel?: undefined;
|
|
11
8
|
href?: undefined;
|
|
12
9
|
} | {
|
|
10
|
+
"data-fimo-spa-shell"?: undefined;
|
|
13
11
|
title?: undefined;
|
|
14
|
-
|
|
12
|
+
property: string;
|
|
15
13
|
content: string;
|
|
16
|
-
property?: undefined;
|
|
17
14
|
tagName?: undefined;
|
|
18
15
|
rel?: undefined;
|
|
19
16
|
href?: undefined;
|
|
20
17
|
} | {
|
|
18
|
+
"data-fimo-spa-shell": string;
|
|
21
19
|
title?: undefined;
|
|
22
|
-
name?: undefined;
|
|
23
20
|
property: string;
|
|
24
21
|
content: string;
|
|
25
22
|
tagName?: undefined;
|
|
26
23
|
rel?: undefined;
|
|
27
24
|
href?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
"data-fimo-spa-shell"?: undefined;
|
|
27
|
+
title?: undefined;
|
|
28
|
+
name: string;
|
|
29
|
+
content: string;
|
|
30
|
+
tagName?: undefined;
|
|
31
|
+
rel?: undefined;
|
|
32
|
+
href?: undefined;
|
|
33
|
+
} | {
|
|
34
|
+
"data-fimo-spa-shell": string;
|
|
35
|
+
title?: undefined;
|
|
36
|
+
name: string;
|
|
37
|
+
content: string;
|
|
38
|
+
tagName?: undefined;
|
|
39
|
+
rel?: undefined;
|
|
40
|
+
href?: undefined;
|
|
28
41
|
} | {
|
|
29
42
|
title?: undefined;
|
|
30
|
-
name?: undefined;
|
|
31
|
-
property?: undefined;
|
|
32
|
-
content?: undefined;
|
|
33
43
|
tagName: string;
|
|
34
44
|
rel: string;
|
|
35
45
|
href: string;
|
|
@@ -41,33 +51,43 @@ export declare function buildFimoMeta(args: {
|
|
|
41
51
|
matches: readonly unknown[];
|
|
42
52
|
}): ({
|
|
43
53
|
title: string;
|
|
44
|
-
name?: undefined;
|
|
45
|
-
property?: undefined;
|
|
46
|
-
content?: undefined;
|
|
47
54
|
tagName?: undefined;
|
|
48
55
|
rel?: undefined;
|
|
49
56
|
href?: undefined;
|
|
50
57
|
} | {
|
|
58
|
+
"data-fimo-spa-shell"?: undefined;
|
|
51
59
|
title?: undefined;
|
|
52
|
-
|
|
60
|
+
property: string;
|
|
53
61
|
content: string;
|
|
54
|
-
property?: undefined;
|
|
55
62
|
tagName?: undefined;
|
|
56
63
|
rel?: undefined;
|
|
57
64
|
href?: undefined;
|
|
58
65
|
} | {
|
|
66
|
+
"data-fimo-spa-shell": string;
|
|
59
67
|
title?: undefined;
|
|
60
|
-
name?: undefined;
|
|
61
68
|
property: string;
|
|
62
69
|
content: string;
|
|
63
70
|
tagName?: undefined;
|
|
64
71
|
rel?: undefined;
|
|
65
72
|
href?: undefined;
|
|
73
|
+
} | {
|
|
74
|
+
"data-fimo-spa-shell"?: undefined;
|
|
75
|
+
title?: undefined;
|
|
76
|
+
name: string;
|
|
77
|
+
content: string;
|
|
78
|
+
tagName?: undefined;
|
|
79
|
+
rel?: undefined;
|
|
80
|
+
href?: undefined;
|
|
81
|
+
} | {
|
|
82
|
+
"data-fimo-spa-shell": string;
|
|
83
|
+
title?: undefined;
|
|
84
|
+
name: string;
|
|
85
|
+
content: string;
|
|
86
|
+
tagName?: undefined;
|
|
87
|
+
rel?: undefined;
|
|
88
|
+
href?: undefined;
|
|
66
89
|
} | {
|
|
67
90
|
title?: undefined;
|
|
68
|
-
name?: undefined;
|
|
69
|
-
property?: undefined;
|
|
70
|
-
content?: undefined;
|
|
71
91
|
tagName: string;
|
|
72
92
|
rel: string;
|
|
73
93
|
href: string;
|
package/dist/seo.js
CHANGED
|
@@ -8,24 +8,38 @@ const config = rawConfig;
|
|
|
8
8
|
export function getSeoForPath(pathname, routeData) {
|
|
9
9
|
return resolveSeoForPath(pathname, config, routeData);
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Marks the SPA shell's image tags. Social crawlers read only the shell, so it keeps the site image,
|
|
13
|
+
* but React adds the page's image next to it instead of replacing it. In the browser,
|
|
14
|
+
* `buildFimoMeta` removes the marked tags before React renders the page's own.
|
|
15
|
+
*/
|
|
16
|
+
const SPA_SHELL_TAG = 'data-fimo-spa-shell';
|
|
17
|
+
/**
|
|
18
|
+
* `canonical` is undefined for the SPA shell. With `pageTags: false` the description and the
|
|
19
|
+
* social title and description stay out too: React Router adds the page's own next to them,
|
|
20
|
+
* not in place of them. `<title>` stays, since React replaces it.
|
|
21
|
+
*/
|
|
22
|
+
function seoToMeta(seo, canonical, pageTags = true) {
|
|
23
|
+
const description = pageTags ? seo.description : undefined;
|
|
24
|
+
const socialTitle = pageTags ? seo.title : undefined;
|
|
25
|
+
const shellTag = pageTags ? {} : { [SPA_SHELL_TAG]: '' };
|
|
12
26
|
return [
|
|
13
27
|
...(seo.title ? [{ title: seo.title }] : []),
|
|
14
|
-
...(
|
|
28
|
+
...(description ? [{ name: 'description', content: description }] : []),
|
|
15
29
|
...(seo.robots ? [{ name: 'robots', content: seo.robots }] : []),
|
|
16
30
|
...(seo.themeColor ? [{ name: 'theme-color', content: seo.themeColor }] : []),
|
|
17
31
|
{ property: 'og:type', content: 'website' },
|
|
18
32
|
...(seo.siteName ? [{ property: 'og:site_name', content: seo.siteName }] : []),
|
|
19
|
-
...(
|
|
20
|
-
...(
|
|
33
|
+
...(socialTitle ? [{ property: 'og:title', content: socialTitle }] : []),
|
|
34
|
+
...(description ? [{ property: 'og:description', content: description }] : []),
|
|
21
35
|
...(canonical ? [{ property: 'og:url', content: canonical }] : []),
|
|
22
|
-
...(seo.image ? [{ property: 'og:image', content: seo.image }] : []),
|
|
36
|
+
...(seo.image ? [{ property: 'og:image', content: seo.image, ...shellTag }] : []),
|
|
23
37
|
...(seo.locale ? [{ property: 'og:locale', content: seo.locale }] : []),
|
|
24
38
|
{ name: 'twitter:card', content: 'summary_large_image' },
|
|
25
39
|
...(seo.twitterSite ? [{ name: 'twitter:site', content: seo.twitterSite }] : []),
|
|
26
|
-
...(
|
|
27
|
-
...(
|
|
28
|
-
...(seo.image ? [{ name: 'twitter:image', content: seo.image }] : []),
|
|
40
|
+
...(socialTitle ? [{ name: 'twitter:title', content: socialTitle }] : []),
|
|
41
|
+
...(description ? [{ name: 'twitter:description', content: description }] : []),
|
|
42
|
+
...(seo.image ? [{ name: 'twitter:image', content: seo.image, ...shellTag }] : []),
|
|
29
43
|
...(canonical ? [{ tagName: 'link', rel: 'canonical', href: canonical }] : []),
|
|
30
44
|
...(seo.favicon
|
|
31
45
|
? [
|
|
@@ -50,13 +64,21 @@ export function buildFimoMeta(args) {
|
|
|
50
64
|
? (firstMatch.loaderData ?? firstMatch.data)
|
|
51
65
|
: undefined;
|
|
52
66
|
const rootRecord = rootData && typeof rootData === 'object' ? rootData : undefined;
|
|
67
|
+
// The SPA shell is one HTML file served for every path, so only the browser knows which page it shows.
|
|
68
|
+
const isSpaShell = rootRecord?.fimoSpaShell === true;
|
|
69
|
+
if (isSpaShell && typeof document !== 'undefined') {
|
|
70
|
+
// This runs while React renders, before it commits the tags returned below, so React never
|
|
71
|
+
// takes a marked shell tag as the page's own.
|
|
72
|
+
document.head?.querySelectorAll(`meta[${SPA_SHELL_TAG}]`).forEach((tag) => tag.remove());
|
|
73
|
+
}
|
|
53
74
|
const seo = getSeoForPath(pathname, rootRecord?.fimoMetaData);
|
|
54
75
|
if (!seo) {
|
|
55
76
|
return [];
|
|
56
77
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
78
|
+
if (isSpaShell && typeof document === 'undefined') {
|
|
79
|
+
return seoToMeta(seo, undefined, false);
|
|
80
|
+
}
|
|
81
|
+
return seoToMeta(seo, buildCanonicalUrl(seo.url, pathname));
|
|
60
82
|
}
|
|
61
83
|
/**
|
|
62
84
|
* Returns the attributes Fimo injects onto the root `<html>` element.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fimo-react-router",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.1-staging.2",
|
|
4
4
|
"description": "Fimo runtime, routing and build integration for React Router projects. Pairs with the fimo package at the same version.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"react-error-boundary": "^6.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@fimo/tsconfig": "2.10.
|
|
45
|
+
"@fimo/tsconfig": "2.10.1-staging.2",
|
|
46
46
|
"@tanstack/react-query": "^5.80.6",
|
|
47
47
|
"@types/node": "22.18.6",
|
|
48
48
|
"@types/react": "19.2.14",
|
|
49
49
|
"@types/react-dom": "19.2.3",
|
|
50
|
-
"fimo": "2.10.
|
|
51
|
-
"fimo-react": "2.10.
|
|
52
|
-
"fimo-vite": "2.10.
|
|
50
|
+
"fimo": "2.10.1-staging.2",
|
|
51
|
+
"fimo-react": "2.10.1-staging.2",
|
|
52
|
+
"fimo-vite": "2.10.1-staging.2",
|
|
53
53
|
"react": "19.2.4",
|
|
54
54
|
"react-dom": "19.2.4",
|
|
55
55
|
"react-router": "7.18.4",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@tanstack/react-query": "^5.80.6",
|
|
62
|
-
"fimo": "
|
|
62
|
+
"fimo": "2.10.1-staging.2",
|
|
63
63
|
"fimo-react": ">=2.0.1",
|
|
64
64
|
"fimo-vite": ">=2.0.1",
|
|
65
65
|
"react": "^18.2.0 || ^19.0.0",
|