+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / sitemap xml in 7.1 and multilanguage

sitemap xml in 7.1 and multilanguage

4 posts, 0 answered
  1. codicezerouno
    codicezerouno avatar
    21 posts
    Registered:
    02 Feb 2009
    23 Aug 2014
    Link to this post

    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.

  2. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    25 Aug 2014 in reply to codicezerouno
    Link to this post

    Dear codicezerouno

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

    Markus

  3. codicezerouno
    codicezerouno avatar
    21 posts
    Registered:
    02 Feb 2009
    25 Aug 2014 in reply to Markus
    Link to this post

    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.

  4. Vassil Vassilev
     Vassil Vassilev avatar
    308 posts
    Registered:
    21 Jan 2015
    27 Aug 2014
    Link to this post
    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
     
4 posts, 0 answered