sitemap xml in 7.1 and multilanguage

Posted by Community Admin on 04-Aug-2018 08:27

sitemap xml in 7.1 and multilanguage

All Replies

Posted by Community Admin on 23-Aug-2014 00:00

Hi,

I have a multi-language site and I configured sitemap generation following the documentation but I did't find how to get site maps for each language.

Can you help me?

Thanks. Stefano.

Posted by Community Admin on 25-Aug-2014 00:00

Dear codicezerouno

Did you download the sitemap.xml and did you take a look at it?

Markus

Posted by Community Admin on 25-Aug-2014 00:00

Hi Markus,

it's all right, inside I got for each node the urls for each language.

My post was not so clear: I supposed to find an option to have one site map file for each language/domain.

Thank you.

Posted by Community Admin on 27-Aug-2014 00:00

Hello,

We have had similar request in the past and we will definitely write a blogpost about splitting Sitemap for each language.

Here is the code snippet (needs to be added in Global.asax):

const string BOOTSTRAPPED_COMMAND_NAME = "Bootstrapped";
  
       protected void Application_Start(object sender, EventArgs e)
       
           // Attach to bootstrapper initialized event to be able to subscribe for the sitemap events.
           Bootstrapper.Initialized += Bootstrapper_Initialized;
       
  
       void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
       
           if (e.CommandName == BOOTSTRAPPED_COMMAND_NAME)
           
               // Uncomment this and SitemapSearchEnginePinging in order to stop automatically pinging Google and Bing.
               //EventHub.Subscribe<Telerik.Sitefinity.SitemapGenerator.Abstractions.Events.ISitemapSearchEnginePinging>(SitemapSearchEnginePinging);
               EventHub.Subscribe<ISitemapGeneratorBeforeWriting>(BeforeSitemapFileIsWritten);
           
       
  
       //public void SitemapSearchEnginePinging(ISitemapSearchEnginePinging @event)
       //
       //    @event.Cancel = true;
       //
  
       bool hasGenerationInProgress = false;
  
       public void BeforeSitemapFileIsWritten(ISitemapGeneratorBeforeWriting @event)
       
           if (!hasGenerationInProgress)
           
               hasGenerationInProgress = true;
               Dictionary<string, List<SitemapEntry>> entriesPerLanguage = new Dictionary<string, List<SitemapEntry>>();
               @event.Entries.ToList().ForEach(sitemapEntry =>
               
                   // Each page has a single location.
                   if (sitemapEntry.Rels != null)
                   
                       sitemapEntry.Rels.ToList().ForEach(rel =>
                       
                           if (!entriesPerLanguage.ContainsKey(rel.Key))
                           
                               entriesPerLanguage.Add(rel.Key, new List<SitemapEntry>());
                           
                           entriesPerLanguage[rel.Key].Add(new SitemapEntry()
                           
                               LastModified = sitemapEntry.LastModified,
                               Priority = sitemapEntry.Priority,
                               Location = rel.Value
                           );
                       );
                   
               );
  
               SchedulingManager manager = SchedulingManager.GetManager();
               var section = ConfigManager.GetManager().GetSection("SitemapConfig", null, null);
               ConfigElement currentSite = ((ConfigElementCollection)section["siteConfigs"]).FirstOrDefault(elmt => (Guid)elmt["siteId"] == @event.SiteId);
               var taskKey = SitemapScheduledTask.GetTaskKey(@event.SiteId);
               var existingTasks = SchedulingManager.GetTasksFromAllProviders(i => i.Key == taskKey && i.IsRunning).FirstOrDefault();
  
               try
               
                   foreach (var languageKey in entriesPerLanguage)
                   
                       // Create a sitemap file:
                       StandartSitemapGenerator generator = new StandartSitemapGenerator();
  
                       generator.SitemapName = languageKey.Key + "_" + (string)currentSite["sitemapName"];
                       generator.SitemapIndexName = languageKey.Key + "_" + (string)currentSite["sitemapIndexName"];
                       generator.SitemapDirectory = (string)currentSite["directory"];
                       generator.RecordsPerFile = (int)currentSite["urlLimit"];
                       generator.Compress = (bool)currentSite["compress"];
                       generator.SiteId = @event.SiteId;
  
                       @event.Cancel = true;
  
                       generator.Generate(languageKey.Value, new SitemapScheduledTask()
                       
                           Key = taskKey,
                       );
                       // Add it to the index:
                   
               
               finally
               
                   hasGenerationInProgress = false;
               
           
       

I hope this serves you well.

Regards,
Vassil Vassilev
Telerik
 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed