Skip to content

Commit 421a7e4

Browse files
committed
Fixed types for remix integration
1 parent 5faf9d9 commit 421a7e4

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@forge42/seo-tools",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"private": false,
55
"keywords": ["seo", "remix-seo", "seo-tools", "structured-data", "sitemap", "robots", "canonical", "seo-alternate"],
66
"description": "Framework agnostic set of helpers designed to help you create, maintain and develop your SEO",

src/remix/sitemap.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export type SitemapFunction<T> = (
1616
sitemapData: T
1717
) => Promise<SitemapFunctionReturnData> | SitemapFunctionReturnData
1818

19-
const convertRemixPathToUrl = (routes: RouteManifest<Route>, route: Route) => {
20-
let currentRoute: Route | null = route
19+
const convertRemixPathToUrl = (routes: RouteManifest<Route | undefined>, route: Route | undefined) => {
20+
let currentRoute: Route | undefined | null = route
2121
const path = []
2222

2323
while (currentRoute) {
@@ -30,7 +30,7 @@ const convertRemixPathToUrl = (routes: RouteManifest<Route>, route: Route) => {
3030
return output === "" ? "/" : output
3131
}
3232

33-
const createExtendedRoutes = (routes: RouteManifest<ServerRoute>) => {
33+
const createExtendedRoutes = (routes: RouteManifest<ServerRoute | undefined>) => {
3434
return Object.values(routes).map((route) => {
3535
return {
3636
...route,
@@ -45,28 +45,18 @@ const generateRemixSitemapRoutes = async ({
4545
}: {
4646
domain: string
4747
sitemapData?: unknown
48-
routes?: RouteManifest<ServerRoute>
48+
routes: RouteManifest<ServerRoute | undefined>
4949
}) => {
50-
let finalRoutes = routes
51-
if (!finalRoutes) {
52-
// @ts-expect-error - This import exists but is not picked up by the typescript compiler because it's a remix internal
53-
const { routes } = await import("virtual:remix/server-build").catch(() => {
54-
throw new Error(
55-
"Could not find the remix server build. Make sure you have Remix running on Vite and not in SPA mode. Otherwise use the generateSitemap utility."
56-
)
57-
})
58-
finalRoutes = routes
59-
}
6050
// Add the url to each route
61-
const extendedRoutes = createExtendedRoutes(finalRoutes as unknown as RouteManifest<ServerRoute>)
51+
const extendedRoutes = createExtendedRoutes(routes)
6252

6353
const transformedRoutes = await Promise.all(
6454
extendedRoutes.map(async (route) => {
6555
const url = route.url
6656
// We don't want to include the root route in the sitemap
6757
if (route.id === "root") return
6858
// If the route has a module, get the handle
69-
const handle = route.module.handle
59+
const handle = route.module?.handle
7060
// If the route has a sitemap function, call it and return the sitemap entries
7161
if (handle && typeof handle === "object" && "sitemap" in handle && typeof handle.sitemap === "function") {
7262
// Type the function just in case
@@ -107,7 +97,7 @@ export interface RemixSitemapInfo {
10797
/**
10898
* The routes object from the remix server build. If not provided, the utility will try to import it.
10999
*/
110-
routes?: RouteManifest<ServerRoute>
100+
routes: RouteManifest<ServerRoute | undefined>
111101
}
112102

113103
/**

0 commit comments

Comments
 (0)