Code to generate a sitemap

Instead of manually generating a sitemap, we looked at ways to auto-generate a sitemap. This code will automatically generate a sitemap 3 levels deep and is pretty generic. You have to add a macro for each level further that you want to go on your sitemap:

    #macro(navlist $node $indent)
		#set($newindent = $indent + "    ")
        #set($submenu = $node.getNodes("nav:submenu"))
        #if ($node)
            #foreach ($navon in $submenu)
            	#firstlevel ($navon $indent)
    			##Use recursion to get all of the children too
    			#secondlist ($navon $newindent)
            #end 
        #end 
    #end
    
	#macro(secondlist $node2 $indent2)
		#set($newindent2 = $indent2 + "    ")
        #set($submenu2 = $node2.getNodes("nav:submenu"))
        #if ($node2)
            #foreach ($navon2 in $submenu2)
            	#firstlevel ($navon2 $indent2)
				#thirdlist ($navon2 $newindent2)
            #end 
        #end 
	#end
	
	#macro(thirdlist $node3 $indent3)
		#set($newindent3 = $indent3 + "    ")
        #set($submenu3 = $node3.getNodes("nav:submenu"))
        #if ($node3)
            #foreach ($navon3 in $submenu3)
            	#firstlevel ($navon3 $indent3)
            #end 
        #end 
	#end
	
    #macro(firstlevel $node $indent)
        ## this macro processes the first level navons
        #set($title = $tools.esc.html($node.getProperty("rx:displaytitle").String))
    	#set($nav_order = $tools.esc.html($node.getProperty("rx:navbar_order").String))
        #set($landing_page = $node.getProperty("nav:url").String)
        #set($axis = $node.getProperty("nav:axis").String)
        #set($depth = $node.getDepth())
        #if($title != "CMS-Training" && $title != "Documents" && $title != "Images")
            #if ( $landing_page )

				#set($body = "<li>$indent<a href='$landing_page' class='active'>$title</a></li>" )
	
                #set($pspair = $user.psoListTools.asPair($nav_order,$body) )
                #set($adding = $slotlist.add($pspair) )
    		#end
    	#end
	#end
	
#set($slotlist = [])

#navlist($nav.root "")
															
#foreach($item in $tools.sorter.sort($slotlist,"first") )

$item.getSecond()

#end

You can go as deep as you like by running a JSR-170 query that searches for all navons within a site’s folder, and assembling each one using a snippet template that loops back up thru the hierarchy of navons, up to the navtree. This is in 6.5.2. The end product is something like this. Maybe not what you want, but it could be prettified (we will do so eventually, when we have launched more web sites.)