#sitemap filter
4 messages · Page 1 of 1 (latest)
Hi @crystal scroll. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
You can exclude specific pages from your sitemap using the filter function in the sitemap integration configuration. If the filter doesn't seem to work for you, make sure you have the correct syntax and logic in your filter function.
Here's an example of how to use the filter function to exclude a specific page:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
integrations: [
sitemap({
filter: (page) => page !== 'https://stargazers.club/secret-vip-lounge',
}),
],
});
To exclude multiple pages, you can use logical operators like this:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
integrations: [
sitemap({
filter: (page) =>
page !== "https://stargazers.club/secret-vip-lounge-1" &&
page !== "https://stargazers.club/secret-vip-lounge-2" &&
page !== "https://stargazers.club/secret-vip-lounge-3" &&
page !== "https://stargazers.club/secret-vip-lounge-4",
}),
],
});
If you still have issues with the filter function, you can try using the serialize function to exclude pages from your sitemap:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import sitemap from '@astrojs/sitemap';
export default defineConfig({
site: 'https://stargazers.club',
integrations: [
sitemap({
serialize(item) {
if (/exclude-from-sitemap/.test(item.url)) {
return undefined;
}
return item;
},
}),
],
});
In this example, any page with "exclude-from-sitemap" in its URL will be excluded from the sitemap.