Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when content in the blogs folders are missed in the sitemap #70

Merged
merged 2 commits into from
Mar 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace VirtoCommerce.SitemapsModule.Data.Services.SitemapItemRecordProviders
public class StaticContentSitemapItemRecordProvider : SitemapItemRecordProviderBase, ISitemapItemRecordProvider
{
private const string PagesContentType = "pages";
private const string BlogsContentType = "blogs";
private static readonly Regex _headerRegExp = new Regex(@"(?s:^---(.*?)---)");

private readonly ISettingsManager _settingsManager;
Expand Down Expand Up @@ -80,22 +81,35 @@ await _contentService.ItemExistsAsync(PagesContentType, sitemap.StoreId, sitemap

foreach (var url in validSitemapItems)
{
var contentFile = await _contentService.GetFileAsync(PagesContentType, sitemap.StoreId, url);
ContentFile contentFile = null;
var contentType = PagesContentType;
if (await _contentService.ItemExistsAsync(PagesContentType, sitemap.StoreId, url))
{
contentFile = await _contentService.GetFileAsync(PagesContentType, sitemap.StoreId, url);
}
else if (await _contentService.ItemExistsAsync(BlogsContentType, sitemap.StoreId, url))
{
contentType = BlogsContentType;
contentFile = await _contentService.GetFileAsync(BlogsContentType, sitemap.StoreId, url);
}

using (var stream = await _contentService.GetItemStreamAsync(PagesContentType, sitemap.StoreId, url))
if (contentFile != null)
{
var content = stream.ReadToString();
using (var stream = await _contentService.GetItemStreamAsync(contentType, sitemap.StoreId, url))
{
var content = stream.ReadToString();

var frontMatterPermalink = GetPermalink(content, url, contentFile.Url);
var urlTemplate = frontMatterPermalink.ToUrl().TrimStart('/');
var frontMatterPermalink = GetPermalink(content, url, contentFile.Url);
var urlTemplate = frontMatterPermalink.ToUrl().TrimStart('/');

var records = GetSitemapItemRecords(store, blogOptions, urlTemplate, baseUrl);
sitemapItem.ItemsRecords.AddRange(records);
}
var records = GetSitemapItemRecords(store, blogOptions, urlTemplate, baseUrl);
sitemapItem.ItemsRecords.AddRange(records);
}

processedCount++;
progressInfo.Description = $"Content: Have been generated records for {processedCount} of {totalCount} pages";
progressCallback?.Invoke(progressInfo);
processedCount++;
progressInfo.Description = $"Content: Have been generated records for {processedCount} of {totalCount} pages";
progressCallback?.Invoke(progressInfo);
}
}
}
}
Expand All @@ -108,6 +122,12 @@ private async Task LoadPagesRecursivly(string storeId, string folrderUrl, List<s
criteria.FolderUrl = folrderUrl;

var searchResult = await _contentFileService.FilterItemsAsync(criteria);
//In case if we not find any content in the pages try to search in the blogs
if(!searchResult.Any())
{
criteria.ContentType = BlogsContentType;
searchResult = await _contentFileService.FilterItemsAsync(criteria);
}

foreach (var file in searchResult.Where(file => file.Type == "blob" && IsExtensionAllowed(allowedExtensions, file.RelativeUrl)))
{
Expand Down
Loading