N
Nuxt9mo ago
Jelmer

Rendering XML

How can I create an /sitemap.xml route that returns XML instead of HTML? I tried using a server route but I can't use my composable there to fetch the sitemap from GraphQL.
1 Reply
Jelmer
JelmerOP9mo ago
Not much special, imho:
export const useStatamicSitemap = async (options: Options): Promise<Sitemap> => {
const { $statamic } = useNuxtApp();

if (!options.site) {
options.site = $statamic.site.handle;
}

const { data } = await useAsyncQuery<{sitemap: Sitemap}>(sitemapQuery, options);
const sitemap = data?.value?.sitemap;

if (!sitemap) {
throw new Error('Missing sitemap from Statamic.');
}

return sitemap;
};
export const useStatamicSitemap = async (options: Options): Promise<Sitemap> => {
const { $statamic } = useNuxtApp();

if (!options.site) {
options.site = $statamic.site.handle;
}

const { data } = await useAsyncQuery<{sitemap: Sitemap}>(sitemapQuery, options);
const sitemap = data?.value?.sitemap;

if (!sitemap) {
throw new Error('Missing sitemap from Statamic.');
}

return sitemap;
};
Not sure if I can. useAsyncQuery is the way to fetch graphql data. I did not know that, thanks! I will try that.
Want results from more Discord servers?
Add your server