예제 #1
0
        /// <inheritdoc />
        /// <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, true);

            context.Response.Clear();
            context.Response.ContentType = "text/xml";
            doc.Save(context.Response.OutputStream);
            context.Response.End();
        }
        /// <inheritdoc />
        /// <summary>
        /// The crawl.
        /// </summary>
        /// <param name="site">
        /// The site.
        /// </param>
        /// <param name="doc">
        /// The doc.
        /// </param>
        public void Crawl(SiteContext site, XmlDocument doc)
        {
            /*
             *  We're going to crawl the site layer-by-layer which will put the upper levels
             *  of the site nearer the top of the sitemap.xml document as opposed to crawling
             *  the tree by parent/child relationships, which will go deep on each branch before
             *  crawling the entire site.
             */
            var max = Sitecore.Configuration.Settings.MaxTreeDepth;

            var root = site.Database.GetItem(site.StartPath);

            if (root == null)
            {
                return;
            }

            var rootNode = SitemapGenerator.CreateNode(root, site);

            if (rootNode.IsPage && rootNode.IsListedInNavigation && rootNode.ShouldIndex)
            {
                SitemapGenerator.AppendUrlElement(doc, rootNode);
            }

            var path = new StringBuilder("./*");

            for (var i = 0; i < max; i++)
            {
                var items = Query.SelectItems(path.ToString(), root);

                if (items != null)
                {
                    foreach (var item in items)
                    {
                        var node = SitemapGenerator.CreateNode(item, site);

                        if (node.IsPage && node.IsListedInNavigation && node.ShouldIndex)
                        {
                            SitemapGenerator.AppendUrlElement(doc, node);
                        }
                    }
                }

                path.Append("/*");
            }
        }