Generate sitemap.xml in 6.5.10 | Community
Skip to main content
Level 3
Aug 17, 2022 10:13 PM UTC
Solved

Generate sitemap.xml in 6.5.10

Hello,

We are using service pack 6.5.10, and we want to generate a sitemap.xml. Whatever documents I have read so far all talk about the AEMaaCS approach or OSGi config that comes with 6.5.11 or later version. I haven't found anything about the lower versions.

Also, we recently migrated our existing site to AEM. So, we already have a sitemap.xml file from the previous codebase. Is it possible to upload it somewhere in AEM and utilize it?

Thank you!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
ShaileshBassi
ShaileshBassiAccepted solution
New Participant
Aug 18, 2022 11:29 AM UTC

@webdev91 There are 2 options available i.e. on-demand and the scheduled.

As information provided by @b_sravan you can utilize the core components to implement the same. But if you can certain requirement for modifying the content while generating the sitemap, proceed with the scheduler approach.

@Component(service = SitemapGenerator.class)
@ServiceRanking(20)
public class MySitemapGenerator extends ResourceTreeSitemapGenerator {

    @Inject
    private String location;

    @Inject
    private String locations;


    @Override
    protected void addResource(final String name, final Sitemap sitemap, final Resource resource) throws SitemapException {
        Page page = resource.adaptTo(Page.class);
        location = page.getPath() + Constants.HTML_EXTENSION;
        locations = MyUtils.getExternalizedLink(location, resource.getResourceResolver());
        final Url url = sitemap.addUrl(locations);
        final Calendar lastmod = Optional.ofNullable(page.getLastModified())
                .orElse(page.getContentResource()
                        .getValueMap()
                        .get(JcrConstants.JCR_CREATED, Calendar.class));
        if (lastmod != null) {
            url.setLastModified(lastmod.toInstant());
            url.setPriority(2);
        }
    }
}

Sample code where modifying the links for the sitemap.

3 replies

ShaileshBassi
ShaileshBassiAccepted solution
New Participant
Aug 18, 2022 11:29 AM UTC

@webdev91 There are 2 options available i.e. on-demand and the scheduled.

As information provided by @b_sravan you can utilize the core components to implement the same. But if you can certain requirement for modifying the content while generating the sitemap, proceed with the scheduler approach.

@Component(service = SitemapGenerator.class)
@ServiceRanking(20)
public class MySitemapGenerator extends ResourceTreeSitemapGenerator {

    @Inject
    private String location;

    @Inject
    private String locations;


    @Override
    protected void addResource(final String name, final Sitemap sitemap, final Resource resource) throws SitemapException {
        Page page = resource.adaptTo(Page.class);
        location = page.getPath() + Constants.HTML_EXTENSION;
        locations = MyUtils.getExternalizedLink(location, resource.getResourceResolver());
        final Url url = sitemap.addUrl(locations);
        final Calendar lastmod = Optional.ofNullable(page.getLastModified())
                .orElse(page.getContentResource()
                        .getValueMap()
                        .get(JcrConstants.JCR_CREATED, Calendar.class));
        if (lastmod != null) {
            url.setLastModified(lastmod.toInstant());
            url.setPriority(2);
        }
    }
}

Sample code where modifying the links for the sitemap.

Translate
B_Sravan
New Participant
Aug 18, 2022 8:11 AM UTC

Hi @webdev91,

 

Recently Adobe has come up with a core component for the sitemap feature, leaving the ACS commons or Osgi config approach deprecated.

And since you mentioned that this is a recent migration, I would strongly recommend you to use the latest version of core components.

More on new sitemap feature: https://experienceleague.adobe.com/docs/experience-manager-learn/sites/seo/sitemaps.html 

New core components' dependency details : https://github.com/adobe/aem-core-wcm-components 

I hope this answers your question, 
Thank you.

 

Regards,

Sravan

Translate