Skip to content

Commit

Permalink
Breadcrumbs fix!
Browse files Browse the repository at this point in the history
  • Loading branch information
ddxv committed Oct 29, 2024
1 parent b554b00 commit 6563414
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions frontend/src/lib/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script lang="ts" generics="Metadata = any">
import { run } from 'svelte/legacy';
import type { Crumb, ModuleData } from '.././types';
import { onMount } from 'svelte';
Expand Down Expand Up @@ -51,11 +49,11 @@
}
let _crumbs = $state([] as Crumb<Metadata>[]);
run(() => {
_crumbs = [] as Crumb<Metadata>[];
$effect(() => {
let tmpCrumbs = [] as Crumb<Metadata>[];
if (crumbs != undefined) {
// If crumbs array is passed in always use that with highest priority
_crumbs = [...crumbs];
tmpCrumbs = [...crumbs];
} else if (routeId) {
// If there is routeing info, use it to find the page modules and
// subsequently the page titles for each route leading up to the
Expand Down Expand Up @@ -88,15 +86,12 @@
const routeModule =
routeModules === undefined ? undefined : routeModules[`${completeRoute}+page.svelte`];
_crumbs.push({
tmpCrumbs.push({
// Last crumb gets no url as it is the current page
url: i == paths.length - 1 ? undefined : completeUrl,
title: getPageTitleFromModule(routeModule) || titleSanitizer(path)
});
}
// Force trigger an update
_crumbs = _crumbs;
} else {
// And if there is no route info, simply generate breadcrumbs from the url
// path
Expand All @@ -105,14 +100,13 @@
for (let i = 0; i < paths.length; i++) {
let path = paths[i];
completeUrl += `/${path}`;
_crumbs.push({
tmpCrumbs.push({
title: titleSanitizer(path),
url: i == paths.length - 1 ? undefined : completeUrl
});
}
_crumbs = _crumbs;
}
_crumbs = tmpCrumbs;
});
</script>

Expand Down

0 comments on commit 6563414

Please sign in to comment.