DamianId
DamianId
NNuxt
Created by DamianId on 3/15/2025 in #❓・help
Nuxt 3 - generating dynamic sitemap xml for storyblock
Hello! I installed sitemap module from nuxt modules and I have problem with dynamic generating sitemap for articles. I dont see URL's from dynamic generation on sitemap.xml. I have 5 static routes, and X dynamic routes. I added this code into nuxt config but IDE provide me information that routes is not used:

routes: async () => {
try {
const { useStoryblokApi } = await import('@storyblok/vue');
const storyblokApi = useStoryblokApi();

const version = process.env.NODE_ENV === 'development' ? 'draft' : 'published';
console.log(`[Sitemap] Fetching Storyblok articles with version: ${version}`);

const { data } = await storyblokApi.get('cdn/stories', {
version: version,
starts_with: 'articles/',
per_page: 100
});

if (data && data.stories && data.stories.length > 0) {
console.log(`[Sitemap] Found ${data.stories.length} articles`);

return data.stories.map(story => ({
url: `/articles/${story.slug}`,
lastmod: story.published_at || story.created_at,
changefreq: 'monthly',
priority: 0.8
}));
} else {
console.log('[Sitemap] No articles found in Storyblok');
return [];
}
} catch (error) {
console.error('[Sitemap] Error generating dynamic sitemap entries:', error);
return [];
}
}

routes: async () => {
try {
const { useStoryblokApi } = await import('@storyblok/vue');
const storyblokApi = useStoryblokApi();

const version = process.env.NODE_ENV === 'development' ? 'draft' : 'published';
console.log(`[Sitemap] Fetching Storyblok articles with version: ${version}`);

const { data } = await storyblokApi.get('cdn/stories', {
version: version,
starts_with: 'articles/',
per_page: 100
});

if (data && data.stories && data.stories.length > 0) {
console.log(`[Sitemap] Found ${data.stories.length} articles`);

return data.stories.map(story => ({
url: `/articles/${story.slug}`,
lastmod: story.published_at || story.created_at,
changefreq: 'monthly',
priority: 0.8
}));
} else {
console.log('[Sitemap] No articles found in Storyblok');
return [];
}
} catch (error) {
console.error('[Sitemap] Error generating dynamic sitemap entries:', error);
return [];
}
}
6 replies
NNuxt
Created by DamianId on 3/16/2024 in #❓・help
Nuxt3 - Laravel REST API
Hi! I'm using Nuxt3 with ssr: true and nuxt generate. I want what I do to be SEO-friendly. I plan to use a Laravel REST API for the backend. Is this good for SEO? I need to create a CMS where the client can add, for example, articles. I will display them in Nuxt via the REST API.
14 replies