Beispiel #1
0
        public static IEnumerable <SiteRoute> DiscoverRoutesForSite(Site site)
        {
            var allRoutes = new List <SiteRoute>();


            var pageRepository          = new CmsPageRepository();
            var historicalPageLocations = pageRepository.GetHistoricalPageLocations(site);

            foreach (var location in historicalPageLocations)
            {
                allRoutes.Add(new RedirectPageRoute
                {
                    InternalRedirectPageId = location.PageId,
                    Authority   = site.UriAuthority,
                    Priority    = location.Priority,
                    SiteId      = location.SiteId,
                    VirtualPath = new Uri(location.VirtualPath, UriKind.Relative)
                });
            }

            var associatedSitemap = SitemapBuilder.BuildSitemap(site, ContentEnvironment.Live, SitemapBuilderFilters.All);



            if (associatedSitemap.HomePage != null)
            {
                var homePageRoute = new ContentPageRoute
                {
                    Authority   = site.UriAuthority,
                    Priority    = 0,
                    SiteId      = site.ContentId,
                    PageId      = site.HomepageId,
                    VirtualPath = MakeRelativeUri(site, string.Empty),
                    RequireSsl  = associatedSitemap.HomePage.RequireSsl
                };

                var homepageContentRoutes = DiscoverContentRoutes(associatedSitemap.HomePage, new[] { homePageRoute });
                allRoutes.Add(homePageRoute);
                allRoutes.AddRange(homepageContentRoutes);
            }

            foreach (var childNode in associatedSitemap.ChildNodes)
            {
                allRoutes.AddRange(DiscoverPageRoutesRecursive(childNode, site));
            }



            return(allRoutes);
        }
        public static Sitemap BuildSitemap(Site site, ContentEnvironment environment, Func <CmsPage, bool> sitemapTrim)
        {
            var siteStructure = SiteStructureMapBuilder.BuildStructureMap(site);

            var pageRepostiory = new CmsPageRepository();
            var allPages       = pageRepostiory
                                 .FindContentVersions(null, environment)
                                 .Result
                                 .Where(sitemapTrim)
                                 .ToDictionary(x => x.ContentId);

            var sitemap = new Sitemap();

            if (site.HomepageId != null && allPages.ContainsKey(site.HomepageId.Value))
            {
                sitemap.HomePage = allPages[site.HomepageId.Value];
            }

            AttachChildNodes(sitemap, siteStructure, string.Empty, allPages);
            return(sitemap);
        }