sitemap xml in 7.1 and multilanguage
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.
Dear codicezerouno
Did you download the sitemap.xml and did you take a look at it?
Markus
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.
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;