Example #1
0
        public virtual async Task LoadSitemapItemRecordsAsync(Store store, Sitemap sitemap, string baseUrl, Action <ExportImportProgressInfo> progressCallback = null)
        {
            var progressInfo = new ExportImportProgressInfo();

            var sitemapItemRecords = new List <SitemapItemRecord>();
            var vendorOptions      = new SitemapItemOptions();

            var vendorSitemapItems = sitemap.Items.Where(x => x.ObjectType.EqualsInvariant(SitemapItemTypes.Vendor));
            var vendorIds          = vendorSitemapItems.Select(x => x.ObjectId).ToArray();
            var members            = await MemberService.GetByIdsAsync(vendorIds);

            var totalCount     = members.Length;
            var processedCount = 0;

            progressInfo.Description = $"Vendor: start generating {totalCount} records for vendors";
            progressCallback?.Invoke(progressInfo);

            foreach (var sitemapItem in vendorSitemapItems)
            {
                var vendor = members.FirstOrDefault(x => x.Id == sitemapItem.ObjectId) as Vendor;
                if (vendor != null)
                {
                    sitemapItem.ItemsRecords = GetSitemapItemRecords(store, vendorOptions, sitemap.UrlTemplate, baseUrl, vendor);

                    processedCount++;
                    progressInfo.Description = $"Vendor: generated  {processedCount} of {totalCount} records for vendors";
                    progressCallback?.Invoke(progressInfo);
                }
            }
        }
        public ICollection <SitemapItemRecord> GetSitemapItemRecords(Store store, SitemapItemOptions options, string urlTemplate, string baseUrl, IEntity entity = null)
        {
            var auditableEntity = entity as AuditableEntity;

            var result = new SitemapItemRecord
            {
                ModifiedDate    = auditableEntity != null ? auditableEntity.ModifiedDate.Value : DateTime.UtcNow,
                Priority        = options.Priority,
                UpdateFrequency = options.UpdateFrequency,
                Url             = UrlBuilder.BuildStoreUrl(store, store.DefaultLanguage, urlTemplate, baseUrl, entity)
            };

            if (entity is ISeoSupport seoSupport)
            {
                foreach (var seoInfo in seoSupport.SeoInfos.Where(x => x.IsActive))
                {
                    if (store.Languages.Contains(seoInfo.LanguageCode) && !store.DefaultLanguage.EqualsInvariant(seoInfo.LanguageCode))
                    {
                        var alternate = new SitemapItemAlternateLinkRecord
                        {
                            Language = seoInfo.LanguageCode,
                            Type     = "alternate",
                            Url      = UrlBuilder.BuildStoreUrl(store, seoInfo.LanguageCode, urlTemplate, baseUrl, entity)
                        };
                        result.Alternates.Add(alternate);
                    }
                }
            }
            return(new[] { result }.ToList());
        }
        public virtual Task LoadSitemapItemRecordsAsync(Store store, Sitemap sitemap, string baseUrl, Action <ExportImportProgressInfo> progressCallback = null)
        {
            var progressInfo = new ExportImportProgressInfo();

            var sitemapItemRecords = new List <SitemapItemRecord>();
            var customOptions      = new SitemapItemOptions();
            var customSitemapItems = sitemap.Items.Where(si => si.ObjectType.EqualsInvariant(SitemapItemTypes.Custom)).ToList();
            var totalCount         = customSitemapItems.Count;

            if (totalCount > 0)
            {
                var processedCount = 0;
                progressInfo.Description = $"Custom: Starting records generation for {totalCount} custom items";
                progressCallback?.Invoke(progressInfo);

                foreach (var customSitemapItem in customSitemapItems)
                {
                    customSitemapItem.ItemsRecords = GetSitemapItemRecords(store, customOptions, customSitemapItem.UrlTemplate, baseUrl);
                    processedCount++;
                    progressInfo.Description = $"Custom: Have been generated {processedCount} of {totalCount}  records for custom  items";
                    progressCallback?.Invoke(progressInfo);
                }
            }
            return(Task.CompletedTask);
        }
Example #4
0
        public virtual async Task LoadSitemapItemRecordsAsync(Store store, Sitemap sitemap, string baseUrl, Action <ExportImportProgressInfo> progressCallback = null)
        {
            var progressInfo = new ExportImportProgressInfo();

            var contentBasePath           = $"Pages/{sitemap.StoreId}";
            var storageProvider           = _blobStorageProviderFactory.CreateProvider(contentBasePath);
            var options                   = new SitemapItemOptions();
            var staticContentSitemapItems = sitemap.Items.Where(si => !string.IsNullOrEmpty(si.ObjectType) &&
                                                                (si.ObjectType.EqualsInvariant(SitemapItemTypes.ContentItem) ||
                                                                 si.ObjectType.EqualsInvariant(SitemapItemTypes.Folder)))
                                            .ToList();
            var totalCount = staticContentSitemapItems.Count;

            if (totalCount > 0)
            {
                var processedCount = 0;

                var acceptedFilenameExtensions = SettingsManager.GetValue(ModuleConstants.Settings.General.AcceptedFilenameExtensions.Name, ".md,.html")
                                                 .Split(',')
                                                 .Select(i => i.Trim())
                                                 .Where(i => !string.IsNullOrEmpty(i))
                                                 .ToList();

                progressInfo.Description = $"Content: Starting records generation  for {totalCount} pages";
                progressCallback?.Invoke(progressInfo);

                foreach (var sitemapItem in staticContentSitemapItems)
                {
                    var urls = new List <string>();
                    if (sitemapItem.ObjectType.EqualsInvariant(SitemapItemTypes.Folder))
                    {
                        var searchResult = await storageProvider.SearchAsync(sitemapItem.UrlTemplate, null);

                        var itemUrls = await GetItemUrls(storageProvider, searchResult);

                        foreach (var itemUrl in itemUrls)
                        {
                            var itemExtension = Path.GetExtension(itemUrl);
                            if (!acceptedFilenameExtensions.Any() ||
                                string.IsNullOrEmpty(itemExtension) ||
                                acceptedFilenameExtensions.Contains(itemExtension, StringComparer.OrdinalIgnoreCase))
                            {
                                urls.Add(itemUrl);
                            }
                        }
                    }
                    else if (sitemapItem.ObjectType.EqualsInvariant(SitemapItemTypes.ContentItem))
                    {
                        var item = await storageProvider.GetBlobInfoAsync(sitemapItem.UrlTemplate);

                        if (item != null)
                        {
                            urls.Add(item.RelativeUrl);
                        }
                    }
                    totalCount = urls.Count;

                    foreach (var url in urls)
                    {
                        using (var stream = storageProvider.OpenRead(url))
                        {
                            var content    = stream.ReadToString();
                            var yamlHeader = ReadYamlHeader(content);
                            yamlHeader.TryGetValue("permalink", out var permalinks);
                            var frontMatterPermalink = new FrontMatterPermalink(url.Replace(".md", ""));
                            if (permalinks != null)
                            {
                                frontMatterPermalink = new FrontMatterPermalink(permalinks.FirstOrDefault());
                            }
                            sitemapItem.ItemsRecords.AddRange(GetSitemapItemRecords(store, options, frontMatterPermalink.ToUrl().TrimStart('/'), baseUrl));

                            processedCount++;
                            progressInfo.Description = $"Content: Have been generated records for {processedCount} of {totalCount} pages";
                            progressCallback?.Invoke(progressInfo);
                        }
                    }
                }
            }
        }