private ActionResult RenderArticleListByCategory(IRenderModel model, string tag, int?p) { var tagPage = model.Content as TravelBlog.Models.VirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(VirtualPage)); } //create a master model var masterModel = new MasterModel(model.Content); var contentByTag = Umbraco.GetContentByTag(masterModel, tagPage.Name, p ?? 1, masterModel.PageSize); //this is a special case in the event that a tag contains a '.', when this happens we change it to a '-' // when generating the URL. So if the above doesn't return any tags and the tag contains a '-', then we // will replace them with '.' and do the lookup again if ((contentByTag == null || contentByTag.PostCount == 0) && tagPage.Name.Contains("-")) { contentByTag = Umbraco.GetContentByTag( masterModel, tagPage.Name.Replace('-', '.'), p ?? 1, masterModel.PageSize); } if (contentByTag == null) { return(new HttpNotFoundResult()); } return(GetPagedListView(masterModel, tagPage, contentByTag.Posts, contentByTag.PostCount, p)); }
public ActionResult RenderTagsOrCategoriesRss(ContentModel model, string tagGroup, string baseUrl, int maxItems) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new MasterModel(model.Content.Parent); var contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name, tagGroup, baseUrl, 1, maxItems); //super hack - but this is because we are replacing '.' with '-' in StringExtensions.EncodePath method // so if we get nothing, we'll retry with replacing back if (contentByTag == null) { contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name.Replace('-', '.'), tagGroup, baseUrl, 1, maxItems); } if (contentByTag == null) { return(HttpNotFound()); } var feed = FeedGenerator.GetFeed(rootPageModel, contentByTag.Posts.Take(maxItems)); return(new RssResult(feed, rootPageModel)); }
public ActionResult RenderTagsOrCategoriesRss(RenderModel model, string tagGroup, string baseUrl, int maxItems) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new ListModel(model.Content.Parent); var contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name, tagGroup, baseUrl); var feed = GetFeed(rootPageModel, contentByTag.Posts.Take(maxItems)); return(new RssResult(feed, rootPageModel)); }
private ActionResult RenderByTagOrCategory(RenderModel model, int?p, string tagGroup, string baseUrl) { var tagPage = model.Content as ArticulateVirtualPage; if (tagPage == null) { throw new InvalidOperationException("The RenderModel.Content instance must be of type " + typeof(ArticulateVirtualPage)); } //create a blog model of the main page var rootPageModel = new ListModel(model.Content.Parent); var contentByTag = Umbraco.GetContentByTag(rootPageModel, tagPage.Name, tagGroup, baseUrl); //this is a special case in the event that a tag contains a '.', when this happens we change it to a '-' // when generating the URL. So if the above doesn't return any tags and the tag contains a '-', then we // will replace them with '.' and do the lookup again if (contentByTag == null && tagPage.Name.Contains("-")) { contentByTag = Umbraco.GetContentByTag( rootPageModel, tagPage.Name.Replace('-', '.'), tagGroup, baseUrl); } if (contentByTag == null) { return(new HttpNotFoundResult()); } if (p != null && p.Value == 1) { return(new RedirectToUmbracoPageResult(model.Content, UmbracoContext)); } if (p == null || p.Value <= 0) { p = 1; } //TODO: I wonder about the performance of this - when we end up with thousands of blog posts, // this will probably not be so efficient. I wonder if using an XPath lookup for batches of children // would work? The children count could be cached. I'd rather not put blog posts under 'month' nodes // just for the sake of performance. Hrm.... Examine possibly too. var totalPosts = contentByTag.PostCount; var pageSize = rootPageModel.PageSize; var totalPages = totalPosts == 0 ? 1 : Convert.ToInt32(Math.Ceiling((double)totalPosts / pageSize)); //Invalid page, redirect without pages if (totalPages < p) { return(new RedirectToUmbracoPageResult(model.Content.Parent, UmbracoContext)); } var pager = new PagerModel( pageSize, p.Value - 1, totalPages, totalPages > p ? model.Content.Url.EnsureEndsWith('?') + "p=" + (p + 1) : null, p > 2 ? model.Content.Url.EnsureEndsWith('?') + "p=" + (p - 1) : p > 1 ? model.Content.Url : null); var listModel = new ListModel(tagPage, contentByTag.Posts, pager); return(View(PathHelper.GetThemeViewPath(listModel, "List"), listModel)); }