generated from pascalmartineau/wp-skeleton
fix: GraphQL breadcrumbs and address
This commit is contained in:
@@ -17,6 +17,11 @@ import {
|
||||
TheResource,
|
||||
} from "#components";
|
||||
|
||||
interface BreadcrumbItem {
|
||||
label: string;
|
||||
to?: string;
|
||||
}
|
||||
|
||||
export async function useNodeByUri() {
|
||||
const route = useRoute();
|
||||
const uri = computed(() => route.path);
|
||||
@@ -25,21 +30,34 @@ export async function useNodeByUri() {
|
||||
throw createError({ statusCode: 500, message: "Erreur lors de la récupération du contenu", fatal: true });
|
||||
}
|
||||
const node = data.value?.data.nodeByUri;
|
||||
|
||||
const breadcrumbs: BreadcrumbItem[] = [];
|
||||
if (node?.breadcrumbs) {
|
||||
breadcrumbs.push(
|
||||
...node.breadcrumbs
|
||||
.filter((item: any) => item.label)
|
||||
.map((item: any) => ({
|
||||
label: item.label,
|
||||
to: item.uri || undefined,
|
||||
})),
|
||||
);
|
||||
}
|
||||
|
||||
switch (node?.__typename) {
|
||||
case "Page":
|
||||
return { component: ThePage, node: node as ThePageFragment };
|
||||
return { component: ThePage, node: node as ThePageFragment, breadcrumbs };
|
||||
case "Post":
|
||||
return { component: TheArticle, node: node as TheArticleFragment };
|
||||
return { component: TheArticle, node: node as TheArticleFragment, breadcrumbs };
|
||||
case "Event":
|
||||
return { component: TheEvent, node: node as TheEventFragment };
|
||||
return { component: TheEvent, node: node as TheEventFragment, breadcrumbs };
|
||||
case "Location":
|
||||
return { component: TheLocation, node: node as TheLocationFragment };
|
||||
return { component: TheLocation, node: node as TheLocationFragment, breadcrumbs };
|
||||
case "Membership":
|
||||
return { component: TheMembership, node: node as TheMembershipFragment };
|
||||
return { component: TheMembership, node: node as TheMembershipFragment, breadcrumbs };
|
||||
case "Project":
|
||||
return { component: TheProject, node: node as TheProjectFragment };
|
||||
return { component: TheProject, node: node as TheProjectFragment, breadcrumbs };
|
||||
case "Resource":
|
||||
return { component: TheResource, node: node as TheResourceFragment };
|
||||
return { component: TheResource, node: node as TheResourceFragment, breadcrumbs };
|
||||
default:
|
||||
throw createError({ statusCode: 404, message: "Page non trouvée", fatal: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user