How the stemap.xml is linking with robots.txt | Community
Skip to main content
New Participant
January 24, 2025
Solved

How the stemap.xml is linking with robots.txt

  • January 24, 2025
  • 2 replies
  • 775 views

I have one requirement where i was creating a new test-sitemap.xml and also we are having an existing main sitemap.xml file. I need to linkup the newly created test-sitemap.xml with the existing sitemap.xml. I enabled the sitemap.xml url in robots.txt file as well. I able to see the test-sitemap.xml path in robots.txt but the urls present in test-sitemap.xml is not coming in main sitemap.xml. What was the steps to enable the test-sitemap.xml in main sitemap.xml.

 

In test-sitemap.xml file where we are having all the dynamic build urls these are not the AEM pages.

 

I need to linkup the test-sitemap.xml to the main sitemap.xml. Can you plz provide the steps for this.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by konstantyn_diachenko

Hi @maturubhanu ,

 

In this case, you will need to create own implementation of org.apache.sling.sitemap.spi.generator.SitemapGenerator. I would suggest to use delegation pattern and use OOTB implementation of SitemapGenerator and extend generation logic. See example below:

 

import org.apache.sling.api.resource.Resource; import org.apache.sling.sitemap.SitemapException; import org.apache.sling.sitemap.builder.Sitemap; import org.apache.sling.sitemap.spi.generator.SitemapGenerator; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import java.util.Set; @Component( property = {"service.ranking:Integer=101"}, service = {SitemapGenerator.class} ) public class CustomTreeSitemapGenerator implements SitemapGenerator { @Reference(target = "(component.name=com.adobe.aem.wcm.seo.impl.sitemap.PageTreeSitemapGeneratorImpl)") private SitemapGenerator sitemapGenerator; @Override public Set<String> getNames(Resource sitemapRoot) { return sitemapGenerator.getNames(sitemapRoot); } @Override public Set<String> getOnDemandNames(Resource sitemapRoot) { return sitemapGenerator.getOnDemandNames(sitemapRoot); } @Override public void generate(Resource sitemapRoot, String name, Sitemap sitemap, Context context) throws SitemapException { sitemapGenerator.generate(sitemapRoot, name, sitemap, context); // get your test-sitemap.xml here // read all URLs from where // add them to the sitemap sitemap.addUrl("https://www.example.com/test"); } }

 

Best regards,

Kostiantyn Diachenko.

2 replies

AmitVishwakarma
New Participant
January 24, 2025

To link test-sitemap.xml with main-sitemap.xml, you need to create a sitemap index file (sitemap-index.xml) that lists both main-sitemap.xml and test-sitemap.xml.

Steps1: Create a Sitemap Index (sitemap-index.xml):

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap> <loc>https://www.yourdomain.com/sitemap.xml</loc> </sitemap> <sitemap> <loc>https://www.yourdomain.com/test-sitemap.xml</loc> </sitemap> </sitemapindex>

2. Update robots.txt to point to the sitemap index:

sitemap: https://www.yourdomain.com/sitemap-index.xml

3. Generate test-sitemap.xml dynamically with your URLs, and make sure it's publicly accessible.

Best regards,
Amit Vishwakarma


arunpatidar
New Participant
January 24, 2025

HI @maturubhanu 

how are you generating the different sitemap i.e. main and test-sitemap ? Are you using OOTB Sling sitemap generator?

Please check this if helps

https://stackoverflow.com/questions/39981478/multiple-sitemaps-within-single-sitemap-file 

Arun Patidar
New Participant
January 24, 2025

Hi @arunpatidar ,

 

Thanks for the reply.

 

I am not using any OOTB sitemap generator. In test-sitemap.xml file i am having an list of url's which are not actual AEM pages these url's are just built based on the dynamic response. I need to add these dynamically bult url's to the main sitemap.xml which is having the actual aem page url's.

konstantyn_diachenko
konstantyn_diachenkoAccepted solution
New Participant
January 24, 2025

Hi @maturubhanu ,

 

In this case, you will need to create own implementation of org.apache.sling.sitemap.spi.generator.SitemapGenerator. I would suggest to use delegation pattern and use OOTB implementation of SitemapGenerator and extend generation logic. See example below:

 

import org.apache.sling.api.resource.Resource; import org.apache.sling.sitemap.SitemapException; import org.apache.sling.sitemap.builder.Sitemap; import org.apache.sling.sitemap.spi.generator.SitemapGenerator; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; import java.util.Set; @Component( property = {"service.ranking:Integer=101"}, service = {SitemapGenerator.class} ) public class CustomTreeSitemapGenerator implements SitemapGenerator { @Reference(target = "(component.name=com.adobe.aem.wcm.seo.impl.sitemap.PageTreeSitemapGeneratorImpl)") private SitemapGenerator sitemapGenerator; @Override public Set<String> getNames(Resource sitemapRoot) { return sitemapGenerator.getNames(sitemapRoot); } @Override public Set<String> getOnDemandNames(Resource sitemapRoot) { return sitemapGenerator.getOnDemandNames(sitemapRoot); } @Override public void generate(Resource sitemapRoot, String name, Sitemap sitemap, Context context) throws SitemapException { sitemapGenerator.generate(sitemapRoot, name, sitemap, context); // get your test-sitemap.xml here // read all URLs from where // add them to the sitemap sitemap.addUrl("https://www.example.com/test"); } }

 

Best regards,

Kostiantyn Diachenko.

Kostiantyn DiachenkoCheck out AEM VLT Intellij plugin