Пример #1
0
        /// <summary>
        /// Returns a sitemap.xml document string for the supplied site.
        /// </summary>
        /// <param name="site">The site to crawl.</param>
        /// <param name="forceRegenerate">Whether the document can be retrieved from cache, or whether a fresh document should be generated.</param>
        /// <returns>An XML string representing sitemap.xml document.</returns>
        public static string GetSitemap(SiteContext site, bool forceRegenerate = false)
        {
            var    key    = typeof(SitemapRepository).FullName + site.Name;
            var    cache  = Sitecore.Caching.CacheManager.GetHtmlCache(site);
            string output = null;

            if (cache != null)
            {
                output = cache.GetHtml(key);
            }

            if (SitemapXmlConfiguration.Current.CacheEnabled && cache != null)
            {
                output = cache.GetHtml(key);
            }

            if (forceRegenerate || !SitemapXmlConfiguration.Current.CacheEnabled || output == null)
            {
                var generator = new SitemapGenerator(site.SiteInfo);

                XmlDocument document = generator.Generate();
                output = document.OuterXml;


                if (SitemapXmlConfiguration.Current.CacheEnabled && cache != null)
                {
                    cache.SetHtml(key, output);
                }
            }

            return(output);
        }
Пример #2
0
        private static async Task GenerateSitemap()
        {
            var config = new Config();
            var client = new VocaDbClient(config.SiteRootUrl);

            log.Info("Getting entries from VocaDB");

            var artists = await client.GetArtists();

            var albums = await client.GetAlbums();

            var songs = await client.GetSongs();

            var tags = await client.GetTags();

            log.Info("Generating sitemap");

            var generator = new SitemapGenerator(config.SiteRootUrl, config.SitemapRootUrl);

            generator.Generate(config.OutFolder, new Dictionary <EntryType, IEnumerable <object> > {
                { EntryType.Artist, artists.Cast <object>() },
                { EntryType.Album, albums.Cast <object>() },
                { EntryType.Song, songs.Cast <object>() },
                { EntryType.Tag, tags },
            });
        }
Пример #3
0
        /// <summary>
        /// Returns a sitemap.xml XmlDocument for the supplied site.
        /// </summary>
        /// <param name="site">The site to crawl.</param>
        /// <param name="forceRegenerate">Whether the document can be retrieved from cache, or whether a fresh document should be generated.</param>
        /// <returns>An XML document representing the supplied site's crawl-able links</returns>
        public static XmlDocument GetSitemap(SiteInfo site, bool forceRegenerate = false)
        {
            var key = typeof(SitemapRepository).FullName + site.Name;

            XmlDocument document = null;

            if (SitemapXmlConfiguration.Current.CacheEnabled)
            {
                document = CachingContext.Current.Get <XmlDocument>(key);
            }

            if (document == null || forceRegenerate)
            {
                var generator = new SitemapGenerator(site);

                document = generator.Generate();

                if (SitemapXmlConfiguration.Current.CacheEnabled)
                {
                    var cacheTimeout = site.GetSitemapXmlCacheTimeout();
                    CachingContext.Current.Add(key, document, DateTime.Now.AddMinutes(cacheTimeout));
                }
            }

            return(document);
        }
Пример #4
0
        private static async Task GenerateSitemap()
        {
            var config = new Config();
            var client = new VocaDbClient(config.SiteRootUrl);

            s_log.Info("Getting entries from VocaDB");

            var artists = await client.GetArtists();

            var albums = await client.GetAlbums();

            var events = await client.GetEvents();

            var songs = await client.GetSongs();

            var tags = await client.GetTags();

            s_log.Info("Generating sitemap");

            var generator = new SitemapGenerator(config.SiteRootUrl, config.SitemapRootUrl);

            generator.Generate(config.OutFolder, new Dictionary <EntryType, IEnumerable <EntryReference> > {
                { EntryType.Artist, artists.Select(e => new EntryReference(e)) },
                { EntryType.Album, albums.Select(e => new EntryReference(e)) },
                { EntryType.ReleaseEvent, events.Items.Select(e => new EntryReference(e.Id, e.UrlSlug)) },
                { EntryType.Song, songs.Select(e => new EntryReference(e)) },
                { EntryType.Tag, tags.Items.Select(e => new EntryReference(e.Id, e.UrlSlug)) },
            });
        }
        /// <summary>
        /// Required by IHttpHandler, this is called by ASP.NET when an appropriate URL match is found.
        /// </summary>
        /// <param name="context">The current request context.</param>
        public void ProcessRequest(HttpContext context)
        {
            var doc = SitemapGenerator.Generate(context.Request);

            context.Response.Clear();
            context.Response.ContentType = "text/xml";
            doc.Save(context.Response.OutputStream);
            context.Response.End();
        }
Пример #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType     = "text/xml";
            Response.ContentEncoding = new UTF8Encoding();

            SitemapGenerator sitemapGenerator = new SitemapGenerator();
            string           siteMap          = sitemapGenerator.Generate();

            Response.Write(siteMap);
            Response.End();
        }
Пример #7
0
 /// <summary>
 /// Generates an XML site map.
 /// </summary>
 /// <param name="siteContent">The site content with pre-rendered HTML.</param>
 /// <param name="outputPath">The local output path to write the site map.</param>
 /// <param name="baseUrl">The base Url to use in generating the site map.</param>
 /// <returns></returns>
 private static string MapSite(SiteContent siteContent, string outputPath, string baseUrl)
 {
     try
     {
         var siteMapGenerator = new SitemapGenerator();
         var siteMap1         = siteMapGenerator.Generate(baseUrl, siteContent);
         var siteMapPath      = $"{outputPath}\\sitemap.xml";
         using (var writer = new StreamWriter(siteMapPath))
         {
             writer.WriteLine(siteMap1);
         }
         return(siteMapPath);
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error while mapping site: {ex.Message} - {ex.StackTrace}");
         throw;
     }
 }
Пример #8
0
        private void GetSitemap()
        {
            string sitemapName = WebUtil.GetQueryString("name");

            if (!String.IsNullOrEmpty(sitemapName))
            {
                Item sitemapRoot = Sitecore.Context.Database.GetItem(Sitecore.Context.Site.RootPath + "/Sitemap Module/" + sitemapName);

                if (sitemapRoot != null)
                {
                    SitemapGenerator generator = new SitemapGenerator(sitemapRoot);
                    generator.Generate(Response.Output);
                    Response.Output.Flush();
                }
            }
        }