Expand my Community achievements bar.

SOLVED

How the stemap.xml is linking with robots.txt

Avatar

Level 2

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.

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Level 9

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.

View solution in original post

4 Replies

Avatar

Community Advisor

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

Avatar

Level 2

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.

Avatar

Correct answer by
Level 9

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.

Avatar

Level 7

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