#astro-sitemap duplicates

3 messages · Page 1 of 1 (latest)

rare reef
#

Hello guys, I would like to ask you if astro-sitemap generates sitemap for alternates correctly, because when I asked ChatGPT I was told that I do not have to create <url> block for each page if it is alternate. Could you help me?

void flumeBOT
#

Hi @rare reef. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Hello! Astro Sitemap can generate a sitemap with alternate pages. The serialize function receives a SitemapItem object, which can have a links property containing a list of LinkItem objects for alternate pages, including the parent page. Each LinkItem has two fields: url (the fully-qualified URL for the version of the page for the specified language) and lang (a supported language code targeted by this version of the page) source (https://docs.astro.build/en/guides/integrations-guide/sitemap#serialize).

Here's an example of how to use the serialize function in your 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 (/your-special-page/.test(item.url)) {
          item.changefreq = 'daily';
          item.lastmod = new Date();
          item.priority = 0.9;
        }
        return item;
      },
    }),
  ],
});

This example shows how to add sitemap-specific properties individually. You can modify the serialize function to handle alternate pages as needed.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

Astro Documentation

Learn how to use the @astrojs/sitemap integration in your Astro project.