public async Task Rss20_HasCollection()
        {
            var rw = new FeedGenerator
            {
                HostUrl            = "https://996.icu",
                HeadTitle          = "996 ICU",
                HeadDescription    = "Work 996 and get into ICU",
                Copyright          = "(c) 2020 996.icu",
                Generator          = "Fubao Generator",
                FeedItemCollection = GetFeedItems(),
                TrackBackUrl       = "https://996.icu/trackback",
                MaxContentLength   = 996,
                GeneratorVersion   = "9.9.6"
            };

            using var ms = new MemoryStream();
            await rw.WriteRssStreamAsync(ms);

            await ms.FlushAsync();

            var bytes      = ms.ToArray();
            var xmlContent = Encoding.UTF8.GetString(bytes);

            Assert.IsNotNull(xmlContent);
            Assert.IsTrue(xmlContent.StartsWith(@"<?xml version=""1.0"" encoding=""utf-8""?><rss version=""2.0""><channel><title>996 ICU</title><description>Work 996 and get into ICU</description><link>https://996.icu/trackback</link>"));
        }
예제 #2
0
        public async Task <byte[]> GetRssStreamDataAsync(string categoryName = null)
        {
            IReadOnlyList <FeedEntry> itemCollection = null;

            if (!string.IsNullOrWhiteSpace(categoryName))
            {
                var cat = await _catRepo.GetAsync(c => c.RouteName == categoryName);

                if (cat is null)
                {
                    throw new InvalidDataException($"'{categoryName}' is not found.");
                }

                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{Utils.AppVersion}",
                FeedItemCollection = itemCollection,
                TrackBackUrl       = _baseUrl,
                MaxContentLength   = 0
            };

            using var ms = new MemoryStream();
            await rw.WriteRssStreamAsync(ms);

            await ms.FlushAsync();

            return(ms.ToArray());
        }