Simple site divide by content type and language

Created on 13 August 2024, 3 months ago

Problem/Motivation

We want to construct the following structure using the simple_sitemap:

A list of index sitemaps on each language (24 languages).

example.com/robots.txt

example.com/en-int/sitemap-index.xml
example.com/es-es/sitemap-index.xml
example.com/it-it/sitemap-index.xml
...

On each index, the sitemaps are divided by selected content types (articles, products, categories...)
example.com/en-int/sitemap-index.xml

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.example.com/en-int/sitemaps/products-sitemap.xml</loc>
<lastmod>2024-08-13T09:23:33+00:00</lastmod>
</sitemap>
<sitemap>
<loc>https://www.example.com/en-int/sitemaps/articles-sitemap.xml</loc>
<lastmod>2024-08-13T09:23:33+00:00</lastmod>
</sitemap>
....

And then the URLs.
https://www.example.com/en-int/sitemaps/products-sitemap.xml

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>https://www.example.com/en-int/p/bread</loc>
<lastmod>2024-08-13T09:20:03+00:00</lastmod>
<changefreq>weekly</changefreq>
<image:image>
<image:loc>https://www.example.com/sites/default/files/XXXX.jpg</image:loc>
</image:image>
</url>
....

Currently reviewing the module, it seems like it is impossible to create this structure.
Our current approach was to create a sitemap for each language and each content type, but we have 24 languages and 6 content types, so it creates too many sitemaps on configuration.

Is there a way to divide the sitemaps without creating them on each variant?

💬 Support request
Status

Active

Version

4.1

Component

Code

Created by

🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • 🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

    The QueueWorker queue each sitemap on \Drupal\simple_sitemap\Queue\QueueWorker::queue

    Could be a good place to divide the sitemaps under conditions (languages, content types...).

    public function queue($sitemaps = []): QueueWorker {
      $empty_variants = array_fill_keys(array_keys($sitemaps), TRUE);
      $all_data_sets = [];
     
      foreach ($sitemaps as $variant => $sitemap) {
        if ($sitemap->isEnabled()) {
          foreach ($sitemap->getType()->getUrlGenerators() as $url_generator_id => $url_generator) {
            // @todo Automatically set sitemap.
            foreach ($url_generator->setSitemap($sitemap)->getDataSets() as $data_set) {
              unset($empty_variants[$variant]);
              $all_data_sets[] = [
                'data' => $data_set,
                'sitemap' => $variant,
                'url_generator' => $url_generator_id,
              ];
     
              if (count($all_data_sets) === self::REBUILD_QUEUE_CHUNK_ITEM_SIZE) {
                $this->queueElements($all_data_sets);
                $all_data_sets = [];
              }
            }
          }
        }
      }
     
      if (!empty($all_data_sets)) {
        $this->queueElements($all_data_sets);
      }
      $this->getQueuedElementCount(TRUE);
     
      // Remove all sitemap content of variants which did not yield any queue
      // elements.
      foreach ($empty_variants as $variant => $is_empty) {
        $sitemaps[$variant]->deleteContent();
      }
     
      return $this;
    } 
    

    Example:

        $all_data_sets[] = [
          'data' => $data_set,
          'sitemap' => $variant,
          'variant' => [
            'type' => 'product',
            'language' => 'es-es',
          ],
          'url_generator' => $url_generator_id,
        ];
    
  • Status changed to Fixed about 1 month ago
  • 🇷🇺Russia walkingdexter

    There is no need to divide sitemaps by language. You can simply divide them by content type. URLs for other languages will be automatically included.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024