Exemplo n.º 1
0
        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.");
        }
Exemplo n.º 2
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.");
        }
        public async Task TestAtom10WithCollection()
        {
            var itemCollection = new List <FeedEntry>();

            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-ATOM-{Guid.NewGuid()}.xml");
            await rw.WriteAtom10FileAsync(path);

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