{"id":57175,"date":"2023-04-27T16:03:33","date_gmt":"2023-04-27T10:33:33","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=57175"},"modified":"2024-06-10T15:39:09","modified_gmt":"2024-06-10T10:09:09","slug":"exploring-apache-sling-sitemap-generator-with-customization-in-aem","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/exploring-apache-sling-sitemap-generator-with-customization-in-aem\/","title":{"rendered":"Exploring Apache Sling Sitemap Generator With Customization in AEM"},"content":{"rendered":"<h3><b>Prerequisite<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u00a0<\/span><span style=\"font-weight: 400;\">AEM 6.5 installed with Service Pack 11+ or\u00a0 AEMaaCs SDK.<\/span><\/p>\n<h3><b>What is Apache Sling Sitemap Generator<br \/>\n<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">As we all know, one crucial<\/span><span style=\"font-weight: 400;\">\u00a0aspect of any website is its <\/span><em><b>Sitemap<\/b><\/em><span style=\"font-weight: 400;\">, a file that provides a roadmap of all the pages of a website for search engines to crawl and index the website.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Below is the sample <em><strong>sitemap.xml<\/strong><\/em> file:<\/span><\/p>\n<p><img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/sitemap.png\" \/><\/p>\n<p><span style=\"font-weight: 400;\">The <em><strong>Apache Sling Sitemap Generator<\/strong><\/em> uses <strong>Apache Sling<\/strong> to generate sitemaps dynamically based on the pages and content in an AEM website. This makes it easy for website owners to keep their sitemap up-to-date as they add, modify, or delete pages on their site.<\/span><\/p>\n<h3><b>Setting up Apache Sling Sitemap Generator<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Setting up the <strong>Apache Sling Sitemap Generator<\/strong> in AEM is a straightforward process that involves a few steps:<\/span><\/p>\n<ol>\n<li><b>sling:sitemapRoot property<br \/>\n<span style=\"font-weight: 400;\">There are two approaches:<br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/b><span style=\"font-weight: 400;\"><strong>\u00a0 \u00a0a)<\/strong> We need to paste this property on the page\u2019s <\/span><em><b>jcr:content node<\/b><\/em><span style=\"font-weight: 400;\"> on which we need to generate a <em><strong>sitemap.xml<\/strong><\/em> and its descendant&#8217;s children. It is the boolean property set to <\/span><em><b>TRUE<\/b><\/em><span style=\"font-weight: 400;\">.<br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0<strong>b)<\/strong> Go to Sites &#8212;-&gt; your project&#8212;-&gt; page(where you want to apply this property)&#8212;-&gt; Properties option&#8212;-&gt;Advanced Tab and then check to &#8220;<strong><em>Generate Sitemap<\/em>&#8220;<\/strong> checkbox.<\/span><img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/generateSitemap.png\" \/><\/li>\n<li><b>Sitemap Servlet Configuration (Note: <span style=\"font-weight: 400;\">This step is only required for custom page resource type<\/span>)\n<p><span style=\"font-weight: 400;\">Go to the<\/span> <\/b><em>http:\/\/&lt;host&gt;:&lt;port&gt;\/system\/console\/configMgr<\/em><b><span style=\"font-weight: 400;\"> and search for \u201c<\/span><\/b><em>SitemapServlet<\/em><b><span style=\"font-weight: 400;\">\u201d configuration, and add the page resource type under property \u201c<\/span><\/b><em>sling.servlet.resourceTypes<\/em><b><span style=\"font-weight: 400;\">\u201d.<br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span>\u00a0 \u00a0 \u00a0 <img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/Screenshot-from-2023-04-20-19-30-42.png\" width=\"1126\" height=\"290\" \/><\/b><\/li>\n<li><b>Apache Sling Sitemap \u2013 Scheduler configuration<br \/>\n<span style=\"font-weight: 400;\">It is the Out of the box configuration (<strong><em>OOTB<\/em><\/strong>) provided by <\/span><\/b><strong><em>Apache Sling<\/em><\/strong><b><span style=\"font-weight: 400;\"> which generates the sitemap based on the cron expression under the path &#8220;<\/span><\/b><em>\/var\/sitemap<\/em><b>&#8220;<span style=\"font-weight: 400;\"> for those pages which have the &#8220;<\/span><\/b><em>sling:sitemapRoot<\/em><b>&#8220;<span style=\"font-weight: 400;\"> property as <\/span><\/b><em><span style=\"font-weight: 400;\">TRUE<\/span><\/em><b><span style=\"font-weight: 400;\">.<\/span><\/b><\/p>\n<p>Below is the sample screenshot of the configuration:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/SitemapSchedulerConfig.png\" width=\"1127\" height=\"370\" \/><\/li>\n<\/ol>\n<p><b>Required properties:<\/b> <span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0a) <\/span><em><b>Name<\/b><\/em><span style=\"font-weight: 400;\">: To provide any generic name to the sitemap.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0b) <\/span><em><b>Schedule<\/b><\/em><span style=\"font-weight: 400;\">: A cron expression used to run the sitemap generation job like this \u201c<\/span><b><em>0 0\/5 * * * ?<\/em>\u201d<\/b><span style=\"font-weight: 400;\">.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0c) <\/span><em><b>Search Path<\/b><\/em><span style=\"font-weight: 400;\">: This is the path from where the pages will be searched. We can change the path based on the requirement. By default, it is set to \u201c<\/span><em><b>\/content<\/b><\/em><span style=\"font-weight: 400;\">\u201d.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 The scheduler will run based on the cron expression and the <strong><em>sitemap.xml<\/em><\/strong> file will be generated. Go to <strong><em>http:\/\/&lt;host&gt;:&lt;port&gt;<\/em><\/strong><\/span><strong><em>\/crx\/de<\/em><\/strong><span style=\"font-weight: 400;\"> and search under this path \u201c<\/span><em><b>\/var\/sitemaps<\/b><\/em><span style=\"font-weight: 400;\">\u201d\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <strong><em>sitemap.xml<\/em><\/strong> will be present as shown below in the screenshot:<br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/sitemapFile.png\" width=\"1115\" height=\"183\" \/><\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 We can access the sitemap by adding the <strong><em>sitemap.xml<\/em><\/strong> extension on the page for which we want to generate the sitemap like below\u00a0<\/span><span style=\"font-weight: 400;\"><em><strong>http:\/\/&lt;host&gt;:&lt;port&gt;\/&lt;page-url&gt;.sitemap.xml.<br \/>\n<\/strong><\/em><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/SitemapXMLFileUrl.png\" width=\"1018\" height=\"688\" \/><\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><b>Sitemap Features<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">We can use a few available sitemap features based on our requirements.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><\/p>\n<ol>\n<li><b><b>Excluding Pages Based on Robot Tags<br \/>\n<span style=\"font-weight: 400;\">Go to sites&#8212;-&gt; your project&#8212;-&gt; page(<em>where you want to apply this property<\/em>)&#8212;&gt; properties option&#8212;-&gt; advanced tab and then apply <\/span><em>Robots Tags<\/em><span style=\"font-weight: 400;\"> value to \u201c<\/span><em>noindex<\/em><span style=\"font-weight: 400;\">\u201d.The page on which the above property is set will be deleted from the sitemap. This approach is more useful in the case of individual pages.<\/p>\n<p><\/span><\/b><\/b><img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/SEO.png\" \/><\/li>\n<li><b><b><b><b>Changing Sitemap Storage Location<br \/>\n<span style=\"font-weight: 400;\">We can modify the path where the sitemaps are stored using the OOTB configuration\u00a0 &#8220;<\/span><em>Apache Sling Sitemap Storage Configuration&#8221;<\/em>. <span style=\"font-weight: 400;\">We need to create a new folder by following the same set of rules and permission as provided under \u201c<\/span><em>\/var\/sitemaps<\/em><span style=\"font-weight: 400;\">\u201d.<\/span><\/b><\/b><\/b><\/b>&nbsp;<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/ApacheSlingSitemapStorageConfig.png\" width=\"1131\" height=\"242\" \/><\/li>\n<\/ol>\n<h3><b>Sitemap Customization<br \/>\n<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Recently we experienced a unique use case while implementing Sitemap dynamically in AEM using the <em><strong>Apache Sling Sitemap Generator<\/strong><\/em> tool. <\/span><span style=\"font-weight: 400;\">Here we will learn how to customize the OOTB generation of the sitemap based on the AEM website and business requirements. Some of the customization options are as follows:<\/span><\/p>\n<ol>\n<li><b>Excluding Pages Based on Template Types<br \/>\n<span style=\"font-weight: 400;\">Exclude multiple pages from the sitemap based on the following key factors page template types, page published, etc, by overriding the <\/span><em>shouldInclude<\/em><span style=\"font-weight: 400;\"> method of\u00a0 <\/span><em>ResourceTreeSitemapGenerator<\/em><span style=\"font-weight: 400;\"> class. <\/span><span style=\"font-weight: 400;\">In our use case, we excluded pages based on page template types for that, we created a <strong><em>Custom OSGI Configuration<\/em><\/strong> to exclude the custom template types.<\/span><\/b><\/p>\n<p>Below is the screenshot of the Custom OSGI Configuration:<\/p>\n<p><b><\/b>\u00a0 \u00a0 <img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/CustomOsgiConfiguration.png\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Below is the sample code to override the <\/span><em><b>shouldInclude<\/b><\/em><span style=\"font-weight: 400;\"> method:<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/shouldIncludeMethod.png\" width=\"1111\" height=\"391\" \/><\/p>\n<p><span style=\"font-weight: 400;\">After this step go to <\/span><em><strong>Apache Sling Sitemap \u2013 Scheduler configuration<\/strong><\/em><span style=\"font-weight: 400;\"> and add this above class name to the \u201c<\/span><em><b>includeGenerator<\/b><\/em><span style=\"font-weight: 400;\">\u201d property.<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><br \/>\n<img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/IncludeCustomGeneratorClass.png\" width=\"1125\" height=\"257\" \/><\/li>\n<li><b>Adding Custom Properties<br \/>\n<\/b>We can add or remove custom properties like change frequency, priority, etc. by overriding the <em>addResource<\/em> method from the same <em>ResourceTreeSitemapGenerator <\/em>class.<br \/>\nBelow is the sample code to override the <em>addResource<\/em> method:<\/p>\n<h4><span style=\"font-weight: 400;\"><img decoding=\"async\" loading=\"lazy\" class=\"\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/04\/addResourceMethod.png\" width=\"1125\" height=\"325\" \/><br \/>\n<\/span><\/h4>\n<\/li>\n<li><b>Changing the Sitemap Format<br \/>\n<\/b>The <em>Apache Sling Sitemap Generator<\/em> supports both <em>XML<\/em> and <em>HTML<\/em> sitemap formats.<br \/>\n<b><br \/>\n<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Now that you know how to configure and customize <em><strong>Apache Sling Sitemap Generator<\/strong><\/em>, you can use it according to your requirements and use cases. If you want to know more about the customization features, you can easily explore them.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>Prerequisite \u00a0AEM 6.5 installed with Service Pack 11+ or\u00a0 AEMaaCs SDK. What is Apache Sling Sitemap Generator As we all know, one crucial\u00a0aspect of any website is its Sitemap, a file that provides a roadmap of all the pages of a website for search engines to crawl and index the website. Below is the sample [&hellip;]<\/p>\n","protected":false},"author":1576,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1264},"categories":[5868,446,1],"tags":[4847,4921,5194,1580],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57175"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1576"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=57175"}],"version-history":[{"count":4,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57175\/revisions"}],"predecessor-version":[{"id":57223,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/57175\/revisions\/57223"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=57175"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=57175"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=57175"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}