Ejemplo n.º 1
0
        public void AddSiteMapData(SitemapData sitemapData, XElement urlset, XDocument xmlDocument)
        {
            if (sitemapData == null)
            {
                return;
            }
            var publishOn = sitemapData.PublishOn;

            if (!publishOn.HasValue)
            {
                return;
            }
            var content = publishOn.Value.SitemapDateString();

            urlset.Add(new XElement(SitemapService.RootNamespace + "url",
                                    new XElement(SitemapService.RootNamespace + "loc", sitemapData.AbsoluteUrl),
                                    new XElement(SitemapService.RootNamespace + "lastmod", content)
                                    ));
        }
Ejemplo n.º 2
0
        public void WriteSitemap()
        {
            var sitemapPath = _getSitemapPath.GetPath(_site);;

            SitemapData data      = null;
            var         queryOver = _session.QueryOver <Webpage>()
                                    .Where(x => !x.IsDeleted)
                                    .And(x => x.Site.Id == _site.Id)
                                    .And(x => x.Published)
                                    .And(x => x.IncludeInSitemap);

            queryOver = GetTypesToRemove()
                        .Aggregate(queryOver, (current, type) => current.And(x => x.GetType() != type));

            var list = queryOver
                       .OrderBy(x => x.PublishOn).Desc
                       .SelectList(builder =>
            {
                builder.Select(x => x.PublishOn).WithAlias(() => data.PublishOn);
                builder.Select(x => x.UrlSegment).WithAlias(() => data.Url);
                builder.Select(x => x.RequiresSSL).WithAlias(() => data.RequiresSSL);
                return(builder);
            }).TransformUsing(Transformers.AliasToBean <SitemapData>())
                       .List <SitemapData>().ToList();

            list.AddRange(_additionalSources.SelectMany(x => x.GetAdditionalData()));

            list.ForEach(
                sitemapData =>
                sitemapData.SetAbsoluteUrl(_siteSettings, _site, CurrentRequestData.HomePage.UrlSegment));
            var xmlDocument = new XDocument(new XDeclaration("1.0", "utf-8", null));
            var urlset      = new XElement(RootNamespace + "urlset",
                                           new XAttribute(XNamespace.Xmlns + "image", ImageNameSpace.NamespaceName)
                                           );

            xmlDocument.Add(urlset);

            AppendChildren(list, urlset, xmlDocument);

            File.WriteAllText(sitemapPath, xmlDocument.ToString(SaveOptions.DisableFormatting));
        }