Expand my Community achievements bar.

SOLVED

Custom Sitemap Generator - Sitemap generating relative urls and not absolute

Avatar

Level 2

Hi all,

currently we are set up with a custom sitemap generator that builds the xml files manually and stores it as an asset within the dam. XML files are coming out great except for one issue - we're seeing the relative urls rather than the absolute that are generated on demand through a servlet.

For the custom sitemap generator, we needed a scheduled osgi service so we transitioned to that. But applying the same logic, we're seeing relative urls being returned.

code example:

 

                //Create sitemap entry for each content path that is not marked hidden by authors
                for (Hit hit : result.getHits()) {
                    String path = hit.getPath();
                    Resource resource = resourceResolver.getResource(path);
                    Page page = null;
                    if (resource != null) {
                        page = resource.adaptTo(Page.class);
                    }
                    RobotsPageModel robotsPage = null;
                    if (page != null && page.getContentResource() != null) {
                        robotsPage = page.getContentResource().adaptTo(RobotsPageModel.class);
                    }
                    if (robotsPage != null &&
                            !robotsPage.isNoIndex() &&
                            !robotsPage.isHideNav()) {
                        String url = pageTreeSitemapGenerator.getCanonicalUrl(page).replaceFirst("^/[^/]+/[^/]+", "").replace(".html", "");
                        StringBuilder entry = urlEntries.getOrDefault(url, new StringBuilder());
                        entry.append(URL_TAG + "\n");
                        entry.append(LOC_TAG).append(url).append(LOC_CLOSING_TAG + "\n");
                        addLastMod(entry, page);
                        addAlternates(entry, page, pageTreeSitemapGenerator);
                        addContentType(entry, page);
                        entry.append(URL_CLOSING_TAG + "\n");
                        urlEntries.put(url, entry);
                    }
                }
        
                for (StringBuilder entry : urlEntries.values()) {
                    writer.append(entry.toString());
                }

 

we did notice that when logging, we saw the urls within the author instance showing as relative compared to the published logs as absolute. 

1 Accepted Solution

Avatar

Correct answer by
Level 5

You can try using an externalizer to form an absolute URL. Please refer the following URL - https://medium.com/@toimrank/aem-sitemap-externalize-and-extension-less-url-be916490d2c6

View solution in original post

2 Replies

Avatar

Correct answer by
Level 5

You can try using an externalizer to form an absolute URL. Please refer the following URL - https://medium.com/@toimrank/aem-sitemap-externalize-and-extension-less-url-be916490d2c6