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