Files
cultureat-bak/wp-content/themes/ccat/app/composables/useNodeByUri.ts
Pascal Martineau 4c3f0a26bf
All checks were successful
Deploy WordPress and Nuxt / deploy (push) Successful in 57s
feat: Routes de l'arborescence
2025-09-15 14:38:14 -04:00

47 lines
1.5 KiB
TypeScript

import type {
ThePageFragment,
TheArticleFragment,
TheEventFragment,
TheLocationFragment,
TheMembershipFragment,
TheProjectFragment,
TheResourceFragment,
} from "#graphql-operations";
import {
ThePage,
TheArticle,
TheEvent,
TheLocation,
TheMembership,
TheProject,
TheResource,
} from "#components";
export async function useNodeByUri() {
const route = useRoute();
const uri = computed(() => route.path);
const { data } = await useAsyncGraphqlQuery("nodeByUri", { uri: uri.value }, { graphqlCaching: { client: true } });
if (data.value?.errors?.length) {
throw createError({ statusCode: 500, message: "Erreur lors de la récupération du contenu", fatal: true });
}
const node = data.value?.data.nodeByUri;
switch (node?.__typename) {
case "Page":
return { component: ThePage, node: node as ThePageFragment };
case "Post":
return { component: TheArticle, node: node as TheArticleFragment };
case "Event":
return { component: TheEvent, node: node as TheEventFragment };
case "Location":
return { component: TheLocation, node: node as TheLocationFragment };
case "Membership":
return { component: TheMembership, node: node as TheMembershipFragment };
case "Project":
return { component: TheProject, node: node as TheProjectFragment };
case "Resource":
return { component: TheResource, node: node as TheResourceFragment };
default:
throw createError({ statusCode: 404, message: "Page non trouvée", fatal: true });
}
}