rasengan 1.2.0-beta.0 → 1.2.0-beta.1
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/CHANGELOG.md +2 -0
- package/lib/esm/routing/providers/metadata.js +25 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,43 +10,38 @@ export default function MetadataProvider({ children, }) {
|
|
|
10
10
|
if (typeof window === 'undefined')
|
|
11
11
|
return;
|
|
12
12
|
(async () => {
|
|
13
|
-
const loadersData = routes.map((route) => route.loaderData
|
|
14
|
-
|
|
13
|
+
const loadersData = routes.map((route) => route.loaderData ?? route.data // Normally the route.data is deprecated, we need to consider route.loaderData, but in some cases, it's undefined and I don't know why, that's why we are using route.data instead
|
|
14
|
+
);
|
|
15
|
+
handleInjectMetadata(loadersData);
|
|
15
16
|
})();
|
|
16
17
|
}, [location]);
|
|
17
|
-
const
|
|
18
|
+
const handleInjectMetadata = (loadersData) => {
|
|
18
19
|
// We generate the metadata
|
|
19
20
|
const metadatas = generateMetadata(loadersData.map((item) => item.meta));
|
|
20
21
|
// We get the last metadata
|
|
21
22
|
// This is the metadata of the page
|
|
22
23
|
const leafMetadata = loadersData.at(-1)?.meta;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const metaDescription = document.createElement('meta');
|
|
45
|
-
metaDescription.setAttribute('name', 'description');
|
|
46
|
-
metaDescription.setAttribute('content', leafMetadata.description);
|
|
47
|
-
metaDescription.setAttribute('data-rg', 'true');
|
|
48
|
-
document.head.appendChild(metaDescription);
|
|
49
|
-
}
|
|
24
|
+
// Find all meta tags with data-rg attribute and remove them
|
|
25
|
+
const metaTagsToRemove = document.querySelectorAll('meta[data-rg="true"]');
|
|
26
|
+
metaTagsToRemove.forEach((metaTag) => {
|
|
27
|
+
metaTag.remove();
|
|
28
|
+
});
|
|
29
|
+
// Inject the meta tags
|
|
30
|
+
metadatas.forEach((metaTag) => {
|
|
31
|
+
// Convert React element to string
|
|
32
|
+
const metaTagString = ReactDOMServer.renderToStaticMarkup(metaTag);
|
|
33
|
+
document.head.insertAdjacentHTML('beforeend', metaTagString);
|
|
34
|
+
});
|
|
35
|
+
if (!leafMetadata)
|
|
36
|
+
return;
|
|
37
|
+
// Change the title of the page
|
|
38
|
+
document.title = leafMetadata.title;
|
|
39
|
+
// Change the description of the page
|
|
40
|
+
const metaDescription = document.createElement('meta');
|
|
41
|
+
metaDescription.setAttribute('name', 'description');
|
|
42
|
+
metaDescription.setAttribute('content', leafMetadata.description);
|
|
43
|
+
metaDescription.setAttribute('data-rg', 'true');
|
|
44
|
+
document.head.appendChild(metaDescription);
|
|
50
45
|
};
|
|
51
46
|
return _jsx(_Fragment, { children: children });
|
|
52
47
|
}
|