Skip to main content
Glama

Storyden

by Southclaws
Mozilla Public License 2.0
229
useRoute.ts1.18 kB
import { usePathname } from "next/navigation"; export type Route = { name: RouteName; label: string; }; type RouteName = "index" | "library" | "admin" | "settings"; const routeLabels: Record<RouteName, string> = { index: "Home", library: "Library", admin: "Admin", settings: "Settings", }; const mapping: Record<string, RouteName> = { "/": "index", "/l": "library", "/admin": "admin", "/settings": "settings", }; function routeFromPrefix(prefix: string): Route | undefined { const routeName = mapping[prefix]; if (!routeName) { return undefined; } return { name: routeName, label: routeLabels[routeName], }; } export function useRoute(): Route | undefined { const pathname = usePathname(); if (pathname[0] !== "/") { throw new Error( `useRoute: Invalid pathname "${pathname}". Expected a path starting with "/".`, ); } const parts = pathname.split("/"); if (parts.length < 2) { console.warn("useRoute: unexpected pathname format", pathname); return routeFromPrefix("/"); } const first = parts[1]; const prefix = `/${first}`; const route = routeFromPrefix(prefix); return route; }

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Southclaws/storyden'

If you have feedback or need assistance with the MCP directory API, please join our Discord server