Hi Team,
I am trying to create sitemap.xml file for my AEM sites using org.apache.sling.sitemap Api on AEM as Cloud Service,
Also i am able to genrate sitemap file, but the challenge, I am facing is
I have multi brands sites on same domain,
Like i have www.CAP.edu and www.SAT.edu
The sitemap.xml file I am getting from my logic is:
1. For cap brand site
But i want there should be domain name in each sitemap file.
Expected Result :
1. For cap site
Views
Replies
Total Likes
Hi @AkshaySwamiii ,
You can try to use externalizer in your custom code to get the URLs with domain. Also, if you have multi territory site then you can include country code in it.
Sample code would look something like this:
@Reference
private Externalizer externalizer;
final String location = this.externalizer.publishLink(
userService.getServiceResolver("<sample-resolver>"),
resource.getPath());
Use com.day.cq.commons.impl.ExternalizerImpl.cfg.json system console configuration define as part of config.publish for having externalizer domain as part of every URL as shown below coming as part of Sitemap. It will be different depend on the run mode or environment.
{
"externalizer.domains": [
"publish https://sampledomain.com"
]
}
-Tarun
if i do these changes in my servlet, then servlet is not registering.
My current code is
@Override
protected void addResource(final String name, final Sitemap sitemap, final Resource resource)
throws SitemapException {
final Page page = resource.adaptTo(Page.class);
if (page == null) {
COMMON_LOGGER.logError(CLASS_NAME, resource.getPath());
return;
}
COMMON_LOGGER.logInfo(CLASS_NAME,resource.getPath());
final String location = this.externalizer.externalize(resource);
COMMON_LOGGER.logInfo(CLASS_NAME, location);
// Add URL to sitemap
final Url url = sitemap.addUrl(location);
final Calendar lastmod = Optional.ofNullable(page.getLastModified())
.orElse(page.getContentResource()
.getValueMap()
.get(JcrConstants.JCR_CREATED, Calendar.class));
if (lastmod != null) {
url.setLastModified(lastmod.toInstant());
}
// Dynamically determine changefreq based on logic
final Url.ChangeFrequency changeFrequency = determineChangeFrequency(lastmod);
url.setChangeFrequency(changeFrequency);
// Dynamically determine priority based on logic
final double priority = determinePriority(page);
url.setPriority(priority);
COMMON_LOGGER.logDebug(CLASS_NAME, url.toString());
}
.