Exemplo n.º 1
0
        async Task ISitemapSourceBuilder.BuildAsync(SitemapSource source, SitemapBuilderContext context)
        {
            var tSource = source as TSitemapSource;

            if (tSource != null)
            {
                await BuildSourceAsync(tSource, context);
            }
        }
Exemplo n.º 2
0
        public override async Task BuildSourceAsync(CustomPathSitemapSource source, SitemapBuilderContext context)
        {
            var url = new XElement(Namespace + "url");

            if (await BuildUrlsetMetadataAsync(source, context, url))
            {
                context.Response.ResponseElement.Add(url);
            }
        }
        public async Task BuildAsync(SitemapType sitemap, SitemapBuilderContext context)
        {
            var tSitemap = sitemap as TSitemapType;

            if (tSitemap != null)
            {
                await BuildSitemapTypeAsync(tSitemap, context);
            }
        }
Exemplo n.º 4
0
        private Task <bool> BuildUrlsetMetadataAsync(CustomPathSitemapSource source, SitemapBuilderContext context, XElement url)
        {
            if (BuildUrl(context, source, url))
            {
                PopulateLastMod(source, url);
                PopulateChangeFrequencyPriority(source, url);

                return(Task.FromResult(true));
            }

            return(Task.FromResult(false));
        }
Exemplo n.º 5
0
        public override async Task BuildSitemapTypeAsync(Sitemap sitemap, SitemapBuilderContext context)
        {
            context.Response = new SitemapResponse
            {
                ResponseElement = new XElement(Namespace + "urlset")
            };

            foreach (var source in sitemap.SitemapSources)
            {
                foreach (var sourceBuilder in _sitemapSourceBuilders)
                {
                    await sourceBuilder.BuildAsync(source, context);
                }
            }
        }
Exemplo n.º 6
0
        private bool BuildUrl(SitemapBuilderContext context, CustomPathSitemapSource source, XElement url)
        {
            if (string.IsNullOrEmpty(source.Path))
            {
                return(false);
            }

            // Add ~/ to the path, because the it is inserted without leading /.
            var path = "~/" + source.Path;

            var loc = new XElement(Namespace + "loc");

            loc.Add(context.HostPrefix + context.UrlHelper.Content(path));
            url.Add(loc);
            return(true);
        }
Exemplo n.º 7
0
        public override async Task BuildSitemapTypeAsync(Sitemap sitemap, SitemapBuilderContext context)
        {
            context.Response = new SitemapResponse
            {
                ResponseElement = new XElement(Namespace + "urlset",
                                               new XAttribute(XNamespace.Xmlns + "xsi", SchemaInstance),
                                               new XAttribute(SchemaInstance + "schemaLocation", SchemaLocation))
            };

            foreach (var source in sitemap.SitemapSources)
            {
                foreach (var sourceBuilder in _sitemapSourceBuilders)
                {
                    await sourceBuilder.BuildAsync(source, context);
                }
            }
        }
        public override async Task BuildSitemapTypeAsync(SitemapIndex sitemap, SitemapBuilderContext context)
        {
            context.Response = new SitemapResponse
            {
                ResponseElement = new XElement(Namespace + "sitemapindex",
                                               new XAttribute(XNamespace.Xmlns + "xsi", SchemaInstance),
                                               new XAttribute(SchemaInstance + "schemaLocation", SchemaLocation))
            };

            var indexSource = sitemap.SitemapSources.FirstOrDefault() as SitemapIndexSource;

            if (indexSource == null)
            {
                return;
            }

            var containedSitemaps = (await _sitemapManager.GetSitemapsAsync())
                                    .Where(s => s.Enabled && indexSource.ContainedSitemapIds.Any(id => id == s.SitemapId));

            foreach (var containedSitemap in containedSitemaps)
            {
                var xmlSitemap = new XElement(Namespace + "sitemap");
                var loc        = new XElement(Namespace + "loc");

                var routeValues = new RouteValueDictionary(_sitemapsOptions.GlobalRouteValues)
                {
                    [_sitemapsOptions.SitemapIdKey] = containedSitemap.SitemapId
                };

                loc.Add(context.HostPrefix + context.UrlHelper.Action(routeValues["Action"].ToString(), routeValues));
                xmlSitemap.Add(loc);

                var lastModDate = await _sitemapModifiedDateProvider.GetLastModifiedDateAsync(containedSitemap);

                if (lastModDate.HasValue)
                {
                    var lastMod = new XElement(Namespace + "lastmod");
                    lastMod.Add(lastModDate.GetValueOrDefault().ToString("yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture));
                    xmlSitemap.Add(lastMod);
                }

                context.Response.ResponseElement.Add(xmlSitemap);
            }
        }
Exemplo n.º 9
0
        public async Task <XDocument> BuildAsync(SitemapType sitemap, SitemapBuilderContext context)
        {
            if (!sitemap.Enabled)
            {
                return(null);
            }

            foreach (var sitemapTypeBuilder in _sitemapTypeBuilders)
            {
                await sitemapTypeBuilder.BuildAsync(sitemap, context);

                if (context.Response != null)
                {
                    var document = new XDocument(context.Response.ResponseElement);

                    return(new XDocument(document));
                }
            }

            return(null);
        }
Exemplo n.º 10
0
 public abstract Task BuildSourceAsync(TSitemapSource source, SitemapBuilderContext context);
 public abstract Task BuildSitemapTypeAsync(TSitemapType sitemap, SitemapBuilderContext context);