Exemple #1
0
        public async Task RefreshFeedFileForPostAsync(bool isAtom)
        {
            Logger.LogInformation("Start refreshing feed for posts.");
            var itemCollection = GetPostsAsFeedItems();

            var rw = new SyndicationFeedGenerator
            {
                HostUrl            = _baseUrl,
                HeadTitle          = _blogConfig.FeedSettings.RssTitle,
                HeadDescription    = _blogConfig.FeedSettings.RssDescription,
                Copyright          = _blogConfig.FeedSettings.RssCopyright,
                Generator          = _blogConfig.FeedSettings.RssGeneratorName,
                FeedItemCollection = itemCollection,
                TrackBackUrl       = _baseUrl,
                MaxContentLength   = 0
            };

            if (isAtom)
            {
                Logger.LogInformation("Writing ATOM file.");
                await rw.WriteAtom10FileAsync($@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\feed\posts-atom.xml");
            }
            else
            {
                Logger.LogInformation("Writing RSS file.");
                await rw.WriteRss20FileAsync($@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\feed\posts.xml");
            }

            Logger.LogInformation("Finished writing feed for posts.");
        }
Exemple #2
0
        public async Task RefreshRssFilesForCategoryAsync(string categoryName)
        {
            Logger.LogInformation($"Start refreshing RSS feed for category {categoryName}.");
            var cat = await _categoryRepository.GetAsync(c => c.Title == categoryName);

            if (null != cat)
            {
                var itemCollection = GetPostsAsFeedItems(cat.Id);

                var rw = new SyndicationFeedGenerator
                {
                    HostUrl            = _baseUrl,
                    HeadTitle          = _blogConfig.FeedSettings.RssTitle,
                    HeadDescription    = _blogConfig.FeedSettings.RssDescription,
                    Copyright          = _blogConfig.FeedSettings.RssCopyright,
                    Generator          = _blogConfig.FeedSettings.RssGeneratorName,
                    FeedItemCollection = itemCollection,
                    TrackBackUrl       = _baseUrl,
                    MaxContentLength   = 0
                };

                await rw.WriteRss20FileAsync($@"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}\feed\posts-category-{categoryName}.xml");

                Logger.LogInformation($"Finished refreshing RSS feed for category {categoryName}.");
            }
            else
            {
                Logger.LogWarning($"Trying to refresh rss feed for category {categoryName} but {categoryName} is not found.");
            }
        }
        public async Task RefreshFeedFileAsync(bool isAtom)
        {
            Logger.LogInformation("Start refreshing feed for posts.");
            var itemCollection = await GetFeedEntriesAsync();

            var rw = new SyndicationFeedGenerator
            {
                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
            };

            if (isAtom)
            {
                Logger.LogInformation("Writing ATOM file.");

                var path = Path.Join($"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}", "feed", "posts-atom.xml");
                await rw.WriteAtom10FileAsync(path);
            }
            else
            {
                Logger.LogInformation("Writing RSS file.");

                var path = Path.Join($"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}", "feed",
                                     "posts.xml");
                await rw.WriteRss20FileAsync(path);
            }

            Logger.LogInformation("Finished writing feed for posts.");
        }
        public async Task RefreshRssFilesForCategoryAsync(string categoryName)
        {
            var cat = await _categoryRepository.GetAsync(c => c.RouteName == categoryName);

            if (null != cat)
            {
                Logger.LogInformation($"Start refreshing RSS feed for category {categoryName}.");

                var itemCollection = await GetPostsAsFeedItemsAsync(cat.Id);

                var rw = new SyndicationFeedGenerator
                {
                    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
                };

                var path = Path.Join($"{AppDomain.CurrentDomain.GetData(Constants.DataDirectory)}", "feed", $"posts-category-{categoryName}.xml");

                await rw.WriteRss20FileAsync(path);

                Logger.LogInformation($"Finished refreshing RSS feed for category {categoryName}.");
            }
        }
        public async Task TestRss20WithCollection()
        {
            var rw = new SyndicationFeedGenerator
            {
                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"
            };

            var path = Path.Join(Path.GetTempPath(), $"Moonglade-UT-RSS-{Guid.NewGuid()}.xml");
            await rw.WriteRss20FileAsync(path);

            Assert.IsTrue(File.Exists(path));
        }