Ejemplo n.º 1
0
        public async Task TestWriteOpmlFileAsync()
        {
            var catInfos = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("Work 996", "work-996")
            };
            var siteRootUrl = "https://996.icu";

            var info = new OpmlDoc
            {
                SiteTitle               = $"Work 996 - OPML",
                CategoryInfo            = catInfos,
                HtmlUrl                 = $"{siteRootUrl}/post",
                XmlUrl                  = $"{siteRootUrl}/rss",
                CategoryXmlUrlTemplate  = $"{siteRootUrl}/rss/category/[catTitle]",
                CategoryHtmlUrlTemplate = $"{siteRootUrl}/category/list/[catTitle]"
            };

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

            var writer = new FileSystemOpmlWriter();
            await writer.WriteOpmlFileAsync(path, info);

            Assert.IsTrue(File.Exists(path));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Opml()
        {
            var feedDirectoryPath = Path.Join($"{SiteDataDirectory}", "feed");

            if (!Directory.Exists(feedDirectoryPath))
            {
                Directory.CreateDirectory(feedDirectoryPath);
                Logger.LogInformation($"Created directory '{feedDirectoryPath}'");
            }

            var opmlDataFile = Path.Join($"{SiteDataDirectory}", $"{Constants.OpmlFileName}");

            if (!System.IO.File.Exists(opmlDataFile))
            {
                Logger.LogInformation($"OPML file not found, writing new file on {opmlDataFile}");

                var cats = await _categoryService.GetAllAsync();

                var catInfos = cats.Select(c => new KeyValuePair <string, string>(c.DisplayName, c.RouteName));

                var oi = new OpmlDoc
                {
                    SiteTitle               = $"{_blogConfig.GeneralSettings.SiteTitle} - OPML",
                    CategoryInfo            = catInfos,
                    HtmlUrl                 = $"{SiteRootUrl}/post",
                    XmlUrl                  = $"{SiteRootUrl}/rss",
                    CategoryXmlUrlTemplate  = $"{SiteRootUrl}/rss/category/[catTitle]",
                    CategoryHtmlUrlTemplate = $"{SiteRootUrl}/category/list/[catTitle]"
                };

                var path = Path.Join($"{SiteDataDirectory}", $"{Constants.OpmlFileName}");
                await _fileSystemOpmlWriter.WriteOpmlFileAsync(path, oi);

                Logger.LogInformation("OPML file write completed.");

                if (!System.IO.File.Exists(opmlDataFile))
                {
                    Logger.LogInformation("OPML file still not found, something just went very very wrong...");
                    return(NotFound());
                }
            }

            if (System.IO.File.Exists(opmlDataFile))
            {
                return(PhysicalFile(opmlDataFile, "text/xml"));
            }

            return(NotFound());
        }
Ejemplo n.º 3
0
    public async Task WriteOpmlFile()
    {
        var catInfos = new List <KeyValuePair <string, string> >
        {
            new("Work 996", "work-996")
        };
        var siteRootUrl = "https://996.icu";

        var info = new OpmlDoc
        {
            SiteTitle       = $"Work 996 - OPML",
            ContentInfo     = catInfos,
            HtmlUrl         = $"{siteRootUrl}/post",
            XmlUrl          = $"{siteRootUrl}/rss",
            XmlUrlTemplate  = $"{siteRootUrl}/rss/[catTitle]",
            HtmlUrlTemplate = $"{siteRootUrl}/category/[catTitle]"
        };

        var handler = new GetOpmlQueryHandler();
        var xml     = await handler.Handle(new(info), default);
Ejemplo n.º 4
0
        public async Task <IActionResult> Opml()
        {
            var cats = await _categoryService.GetAll();

            var catInfos = cats.Select(c => new KeyValuePair <string, string>(c.DisplayName, c.RouteName));
            var rootUrl  = Helper.ResolveRootUrl(HttpContext, _blogConfig.GeneralSettings.CanonicalPrefix);

            var oi = new OpmlDoc
            {
                SiteTitle       = $"{_blogConfig.GeneralSettings.SiteTitle} - OPML",
                ContentInfo     = catInfos,
                HtmlUrl         = $"{rootUrl}/post",
                XmlUrl          = $"{rootUrl}/rss",
                XmlUrlTemplate  = $"{rootUrl}/rss/[catTitle]",
                HtmlUrlTemplate = $"{rootUrl}/category/[catTitle]"
            };

            var xml = await _opmlWriter.GetOpmlDataAsync(oi);

            return(Content(xml, "text/xml"));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Opml([FromServices] IBlogConfig blogConfig, [FromServices] IMemoryStreamOpmlWriter opmlWriter)
        {
            var cats = await _categoryService.GetAllAsync();

            var catInfos = cats.Select(c => new KeyValuePair <string, string>(c.DisplayName, c.RouteName));

            var oi = new OpmlDoc
            {
                SiteTitle               = $"{_blogConfig.GeneralSettings.SiteTitle} - OPML",
                CategoryInfo            = catInfos,
                HtmlUrl                 = $"{ResolveRootUrl(blogConfig)}/post",
                XmlUrl                  = $"{ResolveRootUrl(blogConfig)}/rss",
                CategoryXmlUrlTemplate  = $"{ResolveRootUrl(blogConfig)}/rss/[catTitle]",
                CategoryHtmlUrlTemplate = $"{ResolveRootUrl(blogConfig)}/category/[catTitle]"
            };

            var bytes = await opmlWriter.GetOpmlStreamDataAsync(oi);

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

            return(Content(xmlContent, "text/xml"));
        }
Ejemplo n.º 6
0
        public async Task WriteOpmlFile()
        {
            var catInfos = new List <KeyValuePair <string, string> >
            {
                new("Work 996", "work-996")
            };
            var siteRootUrl = "https://996.icu";

            var info = new OpmlDoc
            {
                SiteTitle               = $"Work 996 - OPML",
                CategoryInfo            = catInfos,
                HtmlUrl                 = $"{siteRootUrl}/post",
                XmlUrl                  = $"{siteRootUrl}/rss",
                CategoryXmlUrlTemplate  = $"{siteRootUrl}/rss/[catTitle]",
                CategoryHtmlUrlTemplate = $"{siteRootUrl}/category/[catTitle]"
            };

            var writer = new MemoryStreamOpmlWriter();
            var bytes  = await writer.GetOpmlStreamDataAsync(info);

            Assert.IsNotNull(bytes);
        }
Ejemplo n.º 7
0
 public GetOpmlQuery(OpmlDoc opmlDoc)
 {
     OpmlDoc = opmlDoc;
 }