Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
TypeScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110import { getDocsPage } from "../docs";import type { MDXData } from "./index";import { getBlogPosts, getChangelogPosts, getComparePages, getCustomerPages, getGuides, getHomePage, getProductPages, getToolingPages, getToolsPages, getUnrelatedPages, getUseCasePages,} from "./index";import { generateListingForPath } from "./listing";
/** * Content resolution result - either MDX content or a generated listing */export type ContentResult = | { type: "mdx"; data: MDXData } | { type: "listing"; data: string };
/** * Resolves pathname to content using two-tier fallback: * 1. Try to find MDX content (blog posts, pages, etc.) * 2. Fallback to generating sitemap-style listings */export function resolveContent(pathname: string): ContentResult | null { // Normalize pathname: remove trailing slash, decode URI const normalizedPath = decodeURIComponent(pathname).replace(/\/$/, "");
// TIER 1: Try to find MDX content first const mdxContent = resolveMdxContent(normalizedPath); if (mdxContent) { return { type: "mdx", data: mdxContent }; }
// TIER 2: Fallback to listing generation const listing = generateListingForPath(normalizedPath); if (listing) { return { type: "listing", data: listing }; }
// Not found return null;}
/** * Resolves pathname to MDX content */function resolveMdxContent(pathname: string): MDXData | null { const segments = pathname.split("/").filter(Boolean);
// Root path โ home.mdx (confirmed: file exists) if (segments.length === 0) { try { return getHomePage(); } catch { // home.mdx doesn't exist, will fallback to listing return null; } }
// Docs use nested slugs (concept/x, sdk/nodejs/x) โ resolve the full tail. if (segments[0] === "docs" && segments.length >= 2) { return getDocsPage(segments.slice(1).join("/")) ?? null; }
// Prefixed paths (category/slug format) const [category, slug] = segments;
// Skip /blog/category/slug pattern (handled by listing generator) if (slug && slug !== "category") { switch (category) { case "blog": return getBlogPosts().find((p) => p.slug === slug) ?? null; case "changelog": return getChangelogPosts().find((p) => p.slug === slug) ?? null; case "compare": return getComparePages().find((p) => p.slug === slug) ?? null; case "customers": return getCustomerPages().find((p) => p.slug === slug) ?? null; case "guides": return getGuides().find((p) => p.slug === slug) ?? null; case "play": return getToolsPages().find((p) => p.slug === slug) ?? null; case "tooling": return getToolingPages().find((p) => p.slug === slug) ?? null; case "use-case": return getUseCasePages().find((p) => p.slug === slug) ?? null; default: return null; } }
// Single segment: try unrelated, then product if (segments.length === 1) { const singleSlug = segments[0]; return ( getUnrelatedPages().find((p) => p.slug === singleSlug) ?? getProductPages().find((p) => p.slug === singleSlug) ?? null ); }
return null;}