public async Task <IActionResult> Blog(string slug) { var post = await _blogCache.GetPost(slug); if (post == null) { return(BlogNotFound()); } var sideLinks = await _blogCache.GetAllLinks(post.Category, post.Slug, 15); var model = new BlogViewModel { Category = post.Category, SideLinks = sideLinks, Post = post }; Response.Headers[HeaderNames.CacheControl] = "no-cache"; return(View(model)); }
public async Task <string> GetRssXml(Category category, string baseAddress) { _logger.LogTrace("Generating RSS XML for category {category}...", category); var xmlDocument = new XmlDocument(); xmlDocument.AppendChild(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null)); var root = CreateElement(xmlDocument, xmlDocument, "rss"); root.SetAttribute("version", "2.0"); var channel = CreateElement(xmlDocument, root, "channel"); CreateElement(xmlDocument, channel, "title", $"Aashish Koirala's {(category == Category.Tech ? "Software & Tech" : "Non-Tech")} Blog"); CreateElement(xmlDocument, channel, "link", baseAddress); CreateElement(xmlDocument, channel, "description", category == Category.Tech ? "Posts about software and software tech, primary around .NET, C#, JS and architecture." : "General non-technical posts about this and that."); CreateElement(xmlDocument, channel, "category", category == Category.Tech ? "Software Development" : "Musings"); CreateElement(xmlDocument, channel, "copyright", $"Copyright (C) {DateTime.Now.Year} Aashish Koirala"); CreateElement(xmlDocument, channel, "language", "en-us"); var image = CreateElement(xmlDocument, channel, "image"); CreateElement(xmlDocument, image, "url", $"{baseAddress}/images/favicons/mstile-150x150.png"); CreateElement(xmlDocument, image, "title", $"Aashish Koirala's {(category == Category.Tech ? "Software & Tech" : "Non-Tech")} Blog"); CreateElement(xmlDocument, image, "link", baseAddress); var links = await _blogCache.GetAllLinks(category, null, _rssItemCount); foreach (var slug in links.Select(x => x.Slug)) { var post = await _blogCache.GetPost(slug); if (post == null) { continue; } var item = CreateElement(xmlDocument, channel, "item"); CreateElement(xmlDocument, item, "title", post.Title); CreateElement(xmlDocument, item, "link", $"{baseAddress}/blog/{slug}"); CreateElement(xmlDocument, item, "description", post.Blurb); } return(xmlDocument.OuterXml); }