{"version":3,"file":"sitemap.js","names":[],"sources":["esm/router/sitemap.js"],"sourcesContent":["import { useMemo } from \"react\";\nimport { removeSupportedExtensions } from \"./matchers\";\nimport { routeNode } from \"./router\";\nimport { sortRoutes } from \"./sortRoutes\";\nfunction useSitemap() {\n  return useMemo(() => getSitemap(routeNode), [routeNode]);\n}\nfunction getSitemap(root) {\n  return root ? mapRouteToSitemap(root, []) : null;\n}\nfunction mapRouteToSitemap(route, parents) {\n  return {\n    contextKey: route.contextKey,\n    filename: getRouteFilename(route),\n    href: getRouteHref(route, parents),\n    isInitial: route.initialRouteName === route.route,\n    isInternal: route.internal ?? false,\n    isGenerated: route.generated ?? false,\n    children: [...route.children].sort(sortRoutes).map((child) => mapRouteToSitemap(child, getRouteSegments(route, parents)))\n  };\n}\nfunction getRouteSegments(route, parents) {\n  return [...parents, ...route.route.split(\"/\")];\n}\nfunction getRouteHref(route, parents) {\n  const path = getRouteSegments(route, parents).map((segment) => segment === \"index\" ? \"\" : segment).filter(Boolean).join(\"/\");\n  return `/${path}`;\n}\nfunction getRouteFilename(route) {\n  const contextKey = removeSupportedExtensions(route.contextKey);\n  const segments = contextKey.split(\"/\");\n  if (route.contextKey.match(/_layout\\.[jt]sx?$/)) {\n    return segments.slice(-2).join(\"/\");\n  }\n  const routeSegmentsCount = route.route.split(\"/\").length;\n  return segments.slice(-routeSegmentsCount).join(\"/\");\n}\nexport {\n  getSitemap,\n  useSitemap\n};\n//# sourceMappingURL=sitemap.js.map\n"],"mappings":";;;;;;AAIA,SAAS,aAAa;CACpB,OAAO,cAAc,WAAW,SAAS,GAAG,CAAC,SAAS,CAAC;AACzD;AACA,SAAS,WAAW,MAAM;CACxB,OAAO,OAAO,kBAAkB,MAAM,CAAC,CAAC,IAAI;AAC9C;AACA,SAAS,kBAAkB,OAAO,SAAS;CACzC,OAAO;EACL,YAAY,MAAM;EAClB,UAAU,iBAAiB,KAAK;EAChC,MAAM,aAAa,OAAO,OAAO;EACjC,WAAW,MAAM,qBA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