Thursday 8 October 2015

Sitecore SiteMap Part 3






In this post we will talk about the code in details according Advanced Sitecore SiteMap module, I will explain the main areas and at the end I will include links to Github repository contains the latest code.



The main code areas contains the following:
  • Generate SiteMap main function.
  • Send SiteMap to search engine.
  • Add SiteMap file name to Robots.txt
  • Sitecore command and SiteMap manual Generation.
  • HTML SiteMap builder function.


A. Generate SiteMap main function

As you can see from the following the code will loop through the sites already defined under the related configuration item and for each site the code will get the start item for each site, then the code will retrieve the available defined languages under sitecore and loop through them and for each decedents item if it is allowed to be included in sitemap by validating the field "Show In Xml SiteMap " the code will read the SiteMap fields section and create the related xml tags; Finally the xml file will be saved into the root folder with the name exists under related configuration item.


B. Send SiteMap to Search Engine
If you enabled sending the generated  SiteMap xml file to search engines and you defined search engines under the related configuration item the following code will loop through the defined search engines and loop through defined sites and send the xml into these search engines.



C. Add SiteMap file name to Robots.txt
The following code simply read the Robots.txt file and add the SiteMap xml path into that file:


D. Sitecore command and SiteMap manual Generation.
In this section I explain how the manual generation of SiteMap will be done. and to implanted I did two things:
1.       Adding related configuration into sitecore commands.config
And to this I just create new configuration file called "Sitecore.AdvancedSiteMap.Commands.GenerateSiteMap.config" and the following is the content of this file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <sitecore>
    <commands>
      <command name="contenteditor:GenerateSiteMap"            type="Sitecore.AdvancedSiteMap.ManualSiteMapGeneration, Sitecore.AdvancedSiteMap"/>
    </commands>
  </sitecore>
</configuration>



2.       Creating the command class "ManualSiteMapGeneration.cs"
It is simple class the inherits " Sitecore.Shell.Framework.Commands.command" and has the following code:




E. HTML SiteMap builder function.
In the following code you will see how HTML SiteMap is being generated using Sitecore advanced SiteMap module


At the end I believe I just provide  a detailed description of all Sitecore Advanced SiteMap module, Also you download the code on the following link:

Sitecore Advanced SiteMap Module 

No comments:

Post a Comment