private async Task <List <Url> > GetPageUrlsAsync(IApi api, Piranha.Models.SitemapItem item, string baseUrl) { var urls = new List <Url>(); if (item.MetaIndex && item.Published.HasValue && item.Published.Value <= DateTime.Now) { urls.Add(new Url { ChangeFrequency = ChangeFrequency.Daily, // If the Permalink contains an absolute Uri (e.g. redirection), don't prefix with the baseUrl Location = Uri.IsWellFormedUriString(item.Permalink, UriKind.Absolute) ? item.Permalink : baseUrl + item.Permalink, Priority = item.MetaPriority, TimeStamp = item.LastModified }); // Get all posts for the blog var posts = await api.Posts.GetAllAsync(item.Id); foreach (var post in posts) { if (post.MetaIndex && post.Published.HasValue && post.Published.Value <= DateTime.Now) { urls.Add(new Url { ChangeFrequency = ChangeFrequency.Daily, // If the Permalink contains an absolute Uri (e.g. redirection), don't prefix with the baseUrl Location = Uri.IsWellFormedUriString(post.Permalink, UriKind.Absolute) ? item.Permalink : baseUrl + post.Permalink, Priority = post.MetaPriority, TimeStamp = post.LastModified }); } } foreach (var child in item.Items) { var childUrls = await GetPageUrlsAsync(api, child, baseUrl).ConfigureAwait(false); if (childUrls.Count > 0) { urls.AddRange(childUrls); } } } return(urls); }
private async Task <List <Url> > GetPageUrlsAsync(IApi api, Piranha.Models.SitemapItem item, string baseUrl) { var urls = new List <Url>(); if (item.Published.HasValue && item.Published.Value <= DateTime.Now) { urls.Add(new Url { ChangeFrequency = ChangeFrequency.Daily, Location = baseUrl + item.Permalink, Priority = 0.5, TimeStamp = item.LastModified }); // Get all posts for the blog var posts = await api.Posts.GetAllAsync(item.Id); foreach (var post in posts) { if (post.Published.HasValue && post.Published.Value <= DateTime.Now) { urls.Add(new Url { ChangeFrequency = ChangeFrequency.Daily, Location = baseUrl + post.Permalink, Priority = 0.5, TimeStamp = post.LastModified }); } } foreach (var child in item.Items) { var childUrls = await GetPageUrlsAsync(api, child, baseUrl).ConfigureAwait(false); if (childUrls.Count > 0) { urls.AddRange(childUrls); } } } return(urls); }