public IActionResult OnGet() { string baseUrl = "https://www.vault.themotte.org"; // get a list of published posts var posts = postLoader.VisiblePosts(); var siteMapBuilder = new SitemapBuilder(); // add the home page to the sitemap siteMapBuilder.AddUrl(baseUrl + "/"); // add the blog posts to the sitemap foreach (var post in posts) { siteMapBuilder.AddUrl(baseUrl + post.FullURL); } var pages = new List <string>() { "about" }; foreach (var staticPage in pages) { siteMapBuilder.AddUrl(baseUrl + "/" + staticPage); } // generate the sitemap xml string xml = siteMapBuilder.ToString(); return(Content(xml, "text/xml")); }
public IActionResult OnGet(string title) { // this is kind of slow and someday should be made less slow Post = postLoader.VisiblePosts().Where(x => x.URLSlug == title).FirstOrDefault(); if (Post == null) { Post = postLoader.VisiblePosts().Where(x => x.RedirectURLSlug.Contains(title)).FirstOrDefault(); if (Post != null) { return(RedirectPermanent(Post.FullURL)); } } if (Post == null) { return(NotFound()); } return(Page()); }
public IActionResult OnGet(int?pageNumber, string categoryName) { Posts = postLoader.VisiblePosts(); if (!string.IsNullOrEmpty(categoryName)) { Posts = Posts.Where(p => p.Category.Contains(categoryName, StringComparer.OrdinalIgnoreCase)).ToList(); if (!Posts.Any()) { return(NotFound()); } } CategoryName = categoryName.Capitalize(); if (!Utilities.Constants.Categories.TryGetValue(categoryName, out CategoryText)) { CategoryText = ""; } return(Page()); }
public IActionResult OnGet() { var items = new List <SyndicationItem>(); foreach (var item in postLoader.VisiblePosts()) { var postUrl = "https://www.vault.themotte.org" + item.FullURL; var title = item.Title; var description = item.BodyExcerptHTML; items.Add(new SyndicationItem(title, description, new Uri(postUrl), item.URLSlug, item.Date)); } var feed = new SyndicationFeed("Motte Quality Contributions", "The best from The Motte", new Uri("https://www.vault.themotte.org/rss"), "RSSUrl", DateTime.Now) { Copyright = new TextSyndicationContent($"{DateTime.Now.Year} Motte Quality Vault"), Items = items, }; var settings = new XmlWriterSettings { Encoding = Encoding.UTF8, NewLineHandling = NewLineHandling.Entitize, NewLineOnAttributes = true, Indent = true }; using (var stream = new MemoryStream()) { using (var xmlWriter = XmlWriter.Create(stream, settings)) { var rssFormatter = new Rss20FeedFormatter(feed, false); rssFormatter.WriteTo(xmlWriter); xmlWriter.Flush(); } return(File(stream.ToArray(), "application/rss+xml; charset=utf-8")); } }
public IActionResult OnGet(int?pageNumber) { Posts = postLoader.VisiblePosts(); return(Page()); }