public HtmlTag IndexPosts() { if (!IndexContent.Any()) { return(HtmlTag.Empty()); } var indexBodyContainer = new DivTag().AddClass("index-posts-container"); foreach (var loopPosts in IndexContent.Take(_numberOfContentItemsToDisplay)) { if (loopPosts.GetType() == typeof(PostContent)) { var post = new SinglePostDiv(loopPosts); var indexPostContentDiv = new DivTag().AddClass("index-posts-content"); indexPostContentDiv.Encoded(false).Text(post.TransformText()); indexBodyContainer.Children.Add(indexPostContentDiv); indexBodyContainer.Children.Add(HorizontalRule.StandardRule()); } if (loopPosts.GetType() == typeof(NoteContent)) { var post = new SingleNoteDiv(loopPosts); var indexPostContentDiv = new DivTag().AddClass("index-posts-content"); indexPostContentDiv.Encoded(false).Text(post.TransformText()); indexBodyContainer.Children.Add(indexPostContentDiv); indexBodyContainer.Children.Add(HorizontalRule.StandardRule()); } if (loopPosts.GetType() == typeof(PhotoContent)) { var post = new SinglePhotoDiv(loopPosts); var indexPostContentDiv = new DivTag().AddClass("index-posts-content"); indexPostContentDiv.Encoded(false).Text(post.TransformText()); indexBodyContainer.Children.Add(indexPostContentDiv); indexBodyContainer.Children.Add(HorizontalRule.StandardRule()); } if (loopPosts.GetType() == typeof(ImageContent)) { var post = new SingleImageDiv(loopPosts); var indexPostContentDiv = new DivTag().AddClass("index-posts-content"); indexPostContentDiv.Encoded(false).Text(post.TransformText()); indexBodyContainer.Children.Add(indexPostContentDiv); indexBodyContainer.Children.Add(HorizontalRule.StandardRule()); } if (loopPosts.GetType() == typeof(FileContent)) { var post = new SingleFileDiv(loopPosts); var indexPostContentDiv = new DivTag().AddClass("index-posts-content"); indexPostContentDiv.Encoded(false).Text(post.TransformText()); indexBodyContainer.Children.Add(indexPostContentDiv); indexBodyContainer.Children.Add(HorizontalRule.StandardRule()); } } return(indexBodyContainer); }
public void WriteRss() { var items = new List <string>(); foreach (var loopPosts in IndexContent) { if (loopPosts.GetType() == typeof(PostContent)) { var post = new SinglePostDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(NoteContent)) { var post = new SingleNoteDiv(loopPosts); var content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(PhotoContent)) { var post = new SinglePostDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } } if (loopPosts.GetType() == typeof(ImageContent)) { var post = new SingleImageDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } if (loopPosts.GetType() == typeof(FileContent)) { var post = new SingleFileDiv(loopPosts); string content = null; if (post.DbEntry.MainPicture != null) { var imageInfo = PictureAssetProcessing.ProcessPictureDirectory(post.DbEntry.MainPicture.Value); if (imageInfo != null) { content = $"{Tags.PictureImgTagDisplayImageOnly(imageInfo)}<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } } if (string.IsNullOrWhiteSpace(content)) { content = $"<p>{HttpUtility.HtmlEncode(post.DbEntry.Summary)}</p>" + $"<p>Read more at <a href=\"https:{post.PageUrl}\">{UserSettingsSingleton.CurrentSettings().SiteName}</a></p>"; } items.Add(RssBuilder.RssItemString(post.DbEntry.Title, $"https:{post.PageUrl}", content, post.DbEntry.CreatedOn, post.DbEntry.ContentId.ToString())); } } var localIndexFile = UserSettingsSingleton.CurrentSettings().LocalSiteRssIndexFeedListFile(); if (localIndexFile.Exists) { localIndexFile.Delete(); localIndexFile.Refresh(); } File.WriteAllText(localIndexFile.FullName, RssBuilder.RssFileString($"{UserSettingsSingleton.CurrentSettings().SiteName}", string.Join(Environment.NewLine, items)), Encoding.UTF8); }