Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Generate sitemap.xml in 6.5.10

Avatar

Level 4

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!

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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.

View solution in original post

3 Replies

Avatar

Community Advisor

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

Avatar

Correct answer by
Community Advisor

@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.