N
Nuxt2w ago
Philip

sitemap module wont show dynamic routes, routes are empty

we tried to create on root ebene ( /server/api/sitemap/urls.ts ) the following
import { asSitemapUrl, defineSitemapEventHandler } from '#imports'

export default defineSitemapEventHandler(async () => {
const [pages, sub_pages, instructions] = await Promise.all([
//
$fetch("$cdnurl$/items/pages").then((p) =>
p.data.map((item) => ({
loc: item.slug,
_sitemap: "pages",
}))
),
$fetch(
"$cdnurl$/items/sub_pages?fields=translations.slug"
).then((sp) =>
sp.data.map((item) => ({
loc: `/support/${item.translations[0].slug}`,
_sitemap: "sub_pages",
}))
),
$fetch(
"$cdnurl$/items/Instructions?fields=translations.slug"
).then((s) =>
s.data.map((p) => ({
loc: `/support/${p.translations[0].slug}`,
_sitemap: "instructions",
}))
),
]);

return [...pages, ...sub_pages, ...instructions].map((p) => asSitemapUrl({
return { loc: p.url, lastmod: p.updatedAt };
}));
});
import { asSitemapUrl, defineSitemapEventHandler } from '#imports'

export default defineSitemapEventHandler(async () => {
const [pages, sub_pages, instructions] = await Promise.all([
//
$fetch("$cdnurl$/items/pages").then((p) =>
p.data.map((item) => ({
loc: item.slug,
_sitemap: "pages",
}))
),
$fetch(
"$cdnurl$/items/sub_pages?fields=translations.slug"
).then((sp) =>
sp.data.map((item) => ({
loc: `/support/${item.translations[0].slug}`,
_sitemap: "sub_pages",
}))
),
$fetch(
"$cdnurl$/items/Instructions?fields=translations.slug"
).then((s) =>
s.data.map((p) => ({
loc: `/support/${p.translations[0].slug}`,
_sitemap: "instructions",
}))
),
]);

return [...pages, ...sub_pages, ...instructions].map((p) => asSitemapUrl({
return { loc: p.url, lastmod: p.updatedAt };
}));
});
in the images you can see our nuxt config. its like we wont even get in to the urls.ts file
No description
No description
18 Replies
Philip
Philip2w ago
this is how the sitemap for "pages" looks like for example
No description
manniL
manniL2w ago
@Philip a running reproduction would be helpful
Philip
Philip2w ago
https://support.utm-shop.de/ this is our live webpage do you want this?
Support für Sophos XGS, Central, AP, RED | UTMshop
Professionelle Unterstützung für Ihre Sophos-Produkte: Technischer Support✓ Fehlerbehebung✓ Einrichtungen✓ RMA✓
manniL
manniL2w ago
no, a full project website (or even a full project source code) is not helpful here In my spare time, I can't go through full projects (that's actually my day job 🙈 )
manniL
manniL2w ago
Stack Overflow
How to create a Minimal, Reproducible Example - Help Center
Stack Overflow | The World’s Largest Online Community for Developers
Philip
Philip2w ago
i totally get this, but what can i provide what makes it easier for you to reproduce? you want a small version which you can just pull and reprodurce?
manniL
manniL2w ago
exactly
Philip
Philip2w ago
ahh i see
manniL
manniL2w ago
ideally a stackblitz so it can run online
Philip
Philip2w ago
i will try to do that thanks
manniL
manniL2w ago
^that's a good starting point
Philip
Philip2w ago
its just i dont really wanna publish our cdn or credentials and to reproduce everything will take ma ton of time 😦 Isnt there a better way? i get you, that you dont wanna reproduce all by yourself. But to create a new directus project cdn etc. just to reproduce this issue is a bit to much dont you think so? our project is quite big and there are some dependencies which are building on each other and i think to reproduce this case is almost like building the project again (4-5 month) a small version of it wouldnt reproduce the issue
manniL
manniL2w ago
What other option do you have in mind? I think a small reproduction just with the sitemap module and some fake data should work, no? and if this works as expected, it is no bug in the module
Philip
Philip2w ago
So i found the solution... the docu is not accurate... instead of this /server/api/sitemap/urls.ts i use this /server/api/sitemap.ts And use the Module in the nuxt.config like in the picture... the docs are not good
No description
Philip
Philip2w ago
import { asSitemapUrl, defineSitemapEventHandler } from "#imports";

export default defineSitemapEventHandler(async () => {
const [pages, subpages, instructions] = await Promise.all([
$fetch("CDN URL/items/pages").then((resp) =>
resp.data.map((item) => {
return {
_path: item.slug,
modifiedAt: new Date(),
};
})
),
$fetch("CDN URL/items/sub_pages?fields=*.*.*").then(
(resp) =>
resp.data.map((item) => {
let url = "/support";
url += item.category
? `/${item.category}/${item.translations[0].slug}`
: `/${item.translations[0].slug}`;

return {
_path: url,
modifiedAt: new Date(),
};
})
),
$fetch("CDN URL/items/Instructions?fields=*.*.*").then(
(resp) =>
resp.data.flatMap((item) => {
var url = "/support/" + item.translations[0].slug + "/anleitungen/";

return item.translations[0].instructions.map((instruction) => {
return {
_path: url + instruction.slug,
modifiedAt: new Date(),
};
});
})
),
]);
return [...pages, ...subpages, ...instructions].map((p) =>
asSitemapUrl({
loc: p._path,
lastmod: p.modifiedAt,
})
);
});
import { asSitemapUrl, defineSitemapEventHandler } from "#imports";

export default defineSitemapEventHandler(async () => {
const [pages, subpages, instructions] = await Promise.all([
$fetch("CDN URL/items/pages").then((resp) =>
resp.data.map((item) => {
return {
_path: item.slug,
modifiedAt: new Date(),
};
})
),
$fetch("CDN URL/items/sub_pages?fields=*.*.*").then(
(resp) =>
resp.data.map((item) => {
let url = "/support";
url += item.category
? `/${item.category}/${item.translations[0].slug}`
: `/${item.translations[0].slug}`;

return {
_path: url,
modifiedAt: new Date(),
};
})
),
$fetch("CDN URL/items/Instructions?fields=*.*.*").then(
(resp) =>
resp.data.flatMap((item) => {
var url = "/support/" + item.translations[0].slug + "/anleitungen/";

return item.translations[0].instructions.map((instruction) => {
return {
_path: url + instruction.slug,
modifiedAt: new Date(),
};
});
})
),
]);
return [...pages, ...subpages, ...instructions].map((p) =>
asSitemapUrl({
loc: p._path,
lastmod: p.modifiedAt,
})
);
});
here our rewritten code for the sitemap.ts ✅
manniL
manniL2w ago
@Philip would you consider sending a PR to improve the doc then? Wäre super 😋
Philip
Philip2w ago
ich gucke mal wie ich Zeit finde 😅 vllt habe ich doch etwas falsch gemacht und durch Zufall einen workaround gefunden. In einem anderem Projekt werde ich nochmal genau das machen was die docs sagen und sollte sich das nochmal bestätigen, dass es nicht funktioniert mit der Ordnerstruktur, dann mache ich einen PR versprochen.
Want results from more Discord servers?
Add your server
More Posts
Stop fetching favico on every requestHi, How could I prevent fetching every request twice, once with the actual data I'm looking for, aExtend NuxtUI Form ComponentI'm using Nuxt UI and I want to extend the UForm component, to always scrol lthe first error into viNuxt does not render updated content after buildI've integrated WordPress for blogs on our site. At the time of build, the blogs that are already thWARN [nuxt] useAsyncData should return a value that is not null or undefined or the request may beWith the latest update i get this multiple times, but there is no way to see which code is the causeDirective v-debounceHello! I have been trying for a while to create a custom directive debounce.ts in Nuxt without succBest way to cache a pre-rendered SSG project?Hello! Currently I am working in a project that aims to prerender using data from a Database around I get an error connected with nuxtui-pro that text-foreground class doesn' t exist in module[2:17:00 AM] ERROR Pre-transform error: [postcss] /node_modules/.pnpm/@nuxt+ui-pro@1.3.1_nuxt@3.11NuxtUI , keep Horizontal Nav Bar item active for multiple routesLet's take for example I have a horizontal route in a shared layout, and I have a route names `docs`nuxt project was working fine 1 month ago now fails on `pnpm run build` prerenderI'm getting many > Error: [500] without more information on the cause or error causing this. The buQuestion about netlify deploymentHey guys… just curious why nuxt docs for deploying to netlify say netlify will automatically set the