Skip to content

Commit

Permalink
Improve getPageTitle function
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Dec 20, 2024
1 parent f3609af commit e8471b3
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions frontend/src/lib/components/Breadcrumbs/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
}
function getPageTitle(): string {
return safeTranslate(
// Check each source in priority order
const title =
$page.data.title ??
($page.data.str || $page.data.name || $breadcrumbs.length > 1
? $breadcrumbs[$breadcrumbs.length - 1]?.label
: URL_MODEL_MAP[$page.url.pathname.split('/').pop() as string]?.verboseNamePlural)
);
$page.data.str ??
$page.data.name ??
getBreadcrumbTitle() ??
getUrlModelTitle();
return safeTranslate(title);
}
function getBreadcrumbTitle(): string | undefined {
return $breadcrumbs.length > 1 ? $breadcrumbs[$breadcrumbs.length - 1]?.label : undefined;
}
function getUrlModelTitle(): string | undefined {
const lastPathSegment = $page.url.pathname.split('/').pop() as string;
return URL_MODEL_MAP[lastPathSegment]?.localNamePlural;
}
afterNavigate(async () => {
Expand Down

0 comments on commit e8471b3

Please sign in to comment.