public void RegisterSitemapToRobotsFile() { string robotsPath = MainUtil.MapPath(string.Concat("/", "robots.txt")); StringBuilder sitemapContent = new StringBuilder(string.Empty); if (File.Exists(robotsPath)) { StreamReader sr = new StreamReader(robotsPath); sitemapContent.Append(sr.ReadToEnd()); sr.Close(); } StreamWriter sw = new StreamWriter(robotsPath, false); foreach (DictionaryEntry site in m_Sites) { string sitemapLine = string.Format("Sitemap: http://{0}/{1}", SitemapManagerConfiguration.GetServerUrlBySite(site.Key.ToString()), site.Value); if (!sitemapContent.ToString().Contains(sitemapLine)) { sitemapContent.AppendLine(sitemapLine); } } sw.Write(sitemapContent.ToString()); sw.Close(); }
private string BuildSitemapIndexXML() { XmlDocument doc = new XmlDocument(); XmlNode declarationNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(declarationNode); XmlNode urlsetNode = doc.CreateElement("sitemapindex"); XmlAttribute xmlnsAttr = doc.CreateAttribute("xmlns"); xmlnsAttr.Value = SitemapManagerConfiguration.XmlnsTpl; urlsetNode.Attributes.Append(xmlnsAttr); doc.AppendChild(urlsetNode); foreach (DictionaryEntry siteEntry in m_Sites) { Site site = Sitecore.Sites.SiteManager.GetSite(siteEntry.Key.ToString()); string filename = siteEntry.Value.ToString(); string serverUrl = SitemapManagerConfiguration.GetServerUrlBySite(site.Name); doc = this.BuildSitemapIndexItem(doc, string.Format("{0}/{1}", serverUrl, filename)); } return(doc.OuterXml); }
public SitemapManager() { m_Sites = SitemapManagerConfiguration.GetSites(); foreach (DictionaryEntry site in m_Sites) { BuildSiteMap(site.Key.ToString(), site.Value.ToString()); } }
private string GetItemUrl(Item item, Site site) { Sitecore.Links.UrlOptions options = Sitecore.Links.UrlOptions.DefaultOptions; options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving; options.Site = SiteContext.GetSite(site.Name); options.AlwaysIncludeServerUrl = false; string url = Sitecore.Links.LinkManager.GetItemUrl(item, options); string serverUrl = SitemapManagerConfiguration.GetServerUrlBySite(site.Name); if (serverUrl.Contains("http://")) { serverUrl = serverUrl.Substring("http://".Length); } StringBuilder sb = new StringBuilder(); if (!string.IsNullOrEmpty(serverUrl)) { if (url.Contains("://") && !url.Contains("http")) { sb.Append("http://"); sb.Append(serverUrl); if (url.IndexOf("/", 3) > 0) { sb.Append(url.Substring(url.IndexOf("/", 3))); } } else { sb.Append("http://"); sb.Append(serverUrl); sb.Append(url); } } else if (!string.IsNullOrEmpty(site.Properties["hostname"])) { sb.Append("http://"); sb.Append(site.Properties["hostname"]); sb.Append(url); } else { if (url.Contains("://") && !url.Contains("http")) { sb.Append("http://"); sb.Append(url); } else { sb.Append(Sitecore.Web.WebUtil.GetFullUrl(url)); } } return(sb.ToString()); }
public SitemapManager() { Database = Factory.GetDatabase(SitemapManagerConfiguration.WorkingDatabase); Assert.IsNotNull(Database, $"Cannot load database for {SitemapManagerConfiguration.WorkingDatabase}"); ConfigItem = Database.GetItem(SitemapManagerConfiguration.SitemapConfigurationItemPath); Assert.IsNotNull(ConfigItem, $"Can not find sitemap config item on path {SitemapManagerConfiguration.SitemapConfigurationItemPath}."); _sites = SitemapManagerConfiguration.GetSites(); foreach (var site in _sites) { BuildSiteMap(site.Key, site.Value); } }
private string GetItemUrl(Item item, Site site) { Sitecore.Links.UrlOptions options = Sitecore.Links.UrlOptions.DefaultOptions; options.SiteResolving = Sitecore.Configuration.Settings.Rendering.SiteResolving; options.Site = SiteContext.GetSite(site.Name); options.AlwaysIncludeServerUrl = false; string serverUrl = SitemapManagerConfiguration.GetServerUrlBySite(site.Name); string itemUrl = Sitecore.Links.LinkManager.GetItemUrl(item, options); if (itemUrl.StartsWith("http")) { return(itemUrl); } else { return(string.Format("{0}{1}", serverUrl, itemUrl)); } }
protected void RefreshButtonClick() { var sh = new SitemapHandler(); sh.RefreshSitemap(this, new EventArgs()); var sites = SitemapManagerConfiguration.GetSites(); var sb = new StringBuilder(); foreach (string sitemapFile in sites.Values) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(sitemapFile); } Message.Text = $" - The sitemap file <b>\"{sb}\"</b> has been refreshed<br /> - <b>\"{sb}\"</b> has been registered to \"robots.txt\""; RefreshPanel("MainPanel"); }
public SitemapManager() { m_Sites = SitemapManagerConfiguration.GetSites(); BuildSitemaps(); }