Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

851 B
Raw Blame
import type { SettingsNav } from "@/components/settings/nav/types";

export type SettingsBreadcrumb = {
  section: string;
  page: string;
};

export function normalizeSettingsPath(pathname: string) {
  return pathname.replace(/\/+$/, "");
}

export function getSettingsBreadcrumb(
  nav: SettingsNav,
  pathname: string,
): SettingsBreadcrumb | null {
  const path = normalizeSettingsPath(pathname);

  for (const group of [nav.account, nav.workspace, nav.admin]) {
    const link = group?.links.find((candidate) => candidate.to === path);
    if (group && link) {
      return { section: group.label, page: link.label };
    }
  }

  for (const project of nav.projects) {
    const link = project.links.find((candidate) => candidate.to === path);
    if (link) {
      return { section: project.name, page: link.label };
    }
  }

  return null;
}