public async Task <string> GetRssDataAsync(string categoryName = null) { IReadOnlyList <FeedEntry> itemCollection; if (!string.IsNullOrWhiteSpace(categoryName)) { var cat = await _catRepo.GetAsync(c => c.RouteName == categoryName); if (cat is null) { return(null); } itemCollection = await GetFeedEntriesAsync(cat.Id); } else { itemCollection = await GetFeedEntriesAsync(); } var rw = new FeedGenerator { HostUrl = _baseUrl, HeadTitle = _blogConfig.FeedSettings.RssTitle, HeadDescription = _blogConfig.FeedSettings.RssDescription, Copyright = _blogConfig.FeedSettings.RssCopyright, Generator = $"Moonglade v{Helper.AppVersion}", FeedItemCollection = itemCollection, TrackBackUrl = _baseUrl }; var xml = await rw.WriteRssAsync(); return(xml); }
public SyndicationService( IOptions <AppSettings> settings, IBlogConfig blogConfig, IHttpContextAccessor httpContextAccessor, IRepository <CategoryEntity> catRepo, IRepository <PostEntity> postRepo) { _settings = settings.Value; _blogConfig = blogConfig; _catRepo = catRepo; _postRepo = postRepo; var acc = httpContextAccessor; _baseUrl = $"{acc.HttpContext.Request.Scheme}://{acc.HttpContext.Request.Host}"; _feedGenerator = new() { HostUrl = _baseUrl, HeadTitle = _blogConfig.FeedSettings.RssTitle, HeadDescription = _blogConfig.FeedSettings.RssDescription, Copyright = _blogConfig.FeedSettings.RssCopyright, Generator = $"Moonglade v{Helper.AppVersion}", TrackBackUrl = _baseUrl }; }
public async Task <string> GetAtomData() { var itemCollection = await GetFeedEntriesAsync(); var rw = new FeedGenerator { HostUrl = _baseUrl, HeadTitle = _blogConfig.FeedSettings.RssTitle, HeadDescription = _blogConfig.FeedSettings.RssDescription, Copyright = _blogConfig.FeedSettings.RssCopyright, Generator = $"Moonglade v{Helper.AppVersion}", FeedItemCollection = itemCollection, TrackBackUrl = _baseUrl }; var xml = await rw.WriteAtomAsync(); return(xml); }