Example #1
0
        protected string GenerateXml(ContentItem startItem, Sitemap result = null)
        {
            IEnumerable<N2.ContentItem> pages = Find.Items
                .Where
                    .Parent.Eq(startItem)
                    .And.Published.Le(DateTime.Now)
                    .And.Type.NotEq(typeof(SitemapXml))                 // Minimize selection as
                    .And.Type.NotEq(typeof(CustomCssContent))           // much as possible
                    .And.Type.NotEq(typeof(CustomJavaScriptContent))
                    .And.Type.NotEq(typeof(RedirectPage))
                    .And.Type.NotEq(typeof(FeedPage))
                    .And.State.NotEq(ContentState.Deleted)
                    .And.State.NotEq(ContentState.Draft)
                    .And.State.NotEq(ContentState.New)
                    .And.State.NotEq(ContentState.Unpublished)
                //.And.State.Eq(ContentState.Published)
                .Select()
                    .Where(item =>
                        item.IsPage
                        && SitemapDecorator.AutoDefineOnType(item.GetType())
                        && !item.GetDetail<bool>(EditModeFields.Syndication.ExcludeFromSiteMapName, false))
                .Union(new N2.ContentItem[] { startItem });

            result = result ?? new Sitemap();
            foreach (N2.ContentItem page in pages)
            {
                string url = (page is WebPage)
                    ? ((WebPage)page).CanonicalUrl //TODO: Fully qualify
                    : page.GetSafeUrl();

                if (!result.Where(item => item.Loc == url).Any())
                {
                    SitemapUrl pageUrl = new SitemapUrl()
                    {
                        LastModifiedDate = page.Updated,
                        Loc = url
                    };
                    result.Add(pageUrl);
                }
                if (page != startItem)
                    GenerateXml(page, result);
            }
            return result.ToString();
        }