{"id":204,"date":"2011-05-02T13:05:58","date_gmt":"2011-05-02T13:05:58","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=204"},"modified":"2011-05-02T13:05:58","modified_gmt":"2011-05-02T13:05:58","slug":"coldfusion-dynamic-sitemap","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/coldfusion-dynamic-sitemap\/","title":{"rendered":"ColdFusion dynamic sitemap"},"content":{"rendered":"<p>I searched the web this morning in hopes that someone has already written a recursive sitemap generator in ColdFusion. It may be out there, but I gave up after browsing page 10 of the Google search for &quot;ColdFusion sitemap&quot;. The results were not entirely unexpected &#8211; they were all examples of creating a dynamic Google sitemap, which requires no presentation.<\/p>\n<p>In the example below, I use CFDirectory recursively to identify all files within a site, then display them with a nested list.<\/p>\n<p><code>&lt;!--- the code below assumes that you have defined your site root in an application variable (a smart thing to do for almost all websites) ---&gt;<br \/>\n\t&lt;cfdirectory directory=&quot;#application.strConfig.webroot#&quot; action=&quot;list&quot; filter=&quot;*.cfm&quot; recurse=&quot;true&quot; sort=&quot;directory ASC, name ASC&quot; name=&quot;files&quot;&gt;<br \/>\n\t&lt;cfset currentDepth = 0&gt;<br \/>\n\t&lt;ul&gt;<br \/>\n\t&lt;cfloop query=&quot;files&quot; endrow=&quot;25&quot;&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfset relativeDir = Replace(directory, application.strConfig.webroot, &quot;&quot;)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;!--- &quot;normalize&quot; the filename, in this case, replace all hypens and underscores with spaces,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; then remove the extension ---&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfset normalizedName = ListFirst(Replace(Replace(name, &quot;-&quot;, &quot; &quot;, &quot;ALL&quot;), &quot;_&quot;, &quot; &quot;, &quot;ALL&quot;), &quot;.&quot;)&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfif ListLen(relativeDir, &quot;\/&quot;) gt currentDepth&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfoutput&gt;&lt;li&gt;#ListLast(relativeDir, &quot;\/&quot;)#&lt;\/cfoutput&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfoutput&gt;&lt;ul&gt;&lt;li&gt;&lt;a href=&quot;#relativeDir#\/#name#&quot;&gt;#normalizedName#&lt;\/a&gt;&lt;\/li&gt;&lt;\/cfoutput&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset currentDepth = currentDepth + 1&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfelseif ListLen(relativeDir, &quot;\/&quot;) lt currentDepth&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfloop from=&quot;#ListLen(relativeDir, &quot;\/&quot;)#&quot; to=&quot;#currentDepth#&quot; index=&quot;i&quot;&gt;&lt;\/ul&gt;&lt;\/li&gt;&lt;\/cfloop&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfoutput&gt;&lt;li&gt;#ListLast(relativeDir, &quot;\/&quot;)#&lt;\/cfoutput&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;ul&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;cfset currentDepth = currentDepth - 1&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;\/cfif&gt;<br \/>\n\t&nbsp;&nbsp;&nbsp; &lt;cfoutput&gt;&lt;li&gt;&lt;a href=&quot;#relativeDir#\/#name#&quot;&gt;#normalizedName#&lt;\/a&gt;&lt;\/li&gt;&lt;\/cfoutput&gt;<br \/>\n\t&lt;\/cfloop&gt;<br \/>\n\t&lt;\/ul&gt;<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I searched the web this morning in hopes that someone has already written a recursive sitemap generator in ColdFusion. It may be out there, but&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[15,34],"tags":[85],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/204"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}