From 900b548f1c5343cb764b2081f15c8f6b4aac476f Mon Sep 17 00:00:00 2001 From: randompete Date: Sat, 31 Dec 2011 12:21:36 +0000 Subject: [PATCH] Fix archive/rsd routes for BlogPart and BlogPostPart --HG-- branch : autoroute --- .../Orchard.Blogs/Routing/BlogAutoroutes.cs | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogAutoroutes.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogAutoroutes.cs index cbb6889c4..9fe02ae4e 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogAutoroutes.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/BlogAutoroutes.cs @@ -5,6 +5,8 @@ using System.Web; using Orchard.Events; using System.Web.Routing; using Orchard.ContentManagement; +using Orchard.Blogs.Models; +using Orchard.Core.Common.Models; namespace Orchard.Blogs.Routing { public interface IAutorouteEventHandler : IEventHandler { @@ -15,57 +17,62 @@ namespace Orchard.Blogs.Routing { public void Routed(IContent content, string path, ICollection> aliases) { // TODO: (PH:Autoroute) Cheap and it works. But could there be a better way? - - // Add RSD route - aliases.Add(Tuple.Create( - path+"/rsd", - new RouteValueDictionary {{"area", "Orchard.Blogs"}, + if (content.Is()) { + // Add RSD route + aliases.Add(Tuple.Create( + path + "/rsd", + new RouteValueDictionary {{"area", "Orchard.Blogs"}, {"controller", "RemoteBlogPublishing"}, {"action", "Rsd"}, {"blogId", content.Id} })); - - // Add Archives routes - var year = "{Content.Date.Format:yyyy}"; - var month = "{Content.Date.Format:MM}"; - var day = "{Content.Date.Format:dd}"; - - aliases.Add(Tuple.Create( - path+"/Archive", - new RouteValueDictionary { + aliases.Add(Tuple.Create( + path + "/Archive", + new RouteValueDictionary { {"area", "Orchard.Blogs"}, {"controller", "BlogPost"}, {"action", "ListByArchive"}, {"blogId", content.Id}, {"archiveData", ""} })); - aliases.Add(Tuple.Create( - path+String.Format("/Archive/{0}",year), - new RouteValueDictionary { + } + + if (content.Is()) { + var pathStart = "{Content.Container.Slug}/Archive/"; + + // Add Archives routes + var year = "{Content.Date.Format:yyyy}"; + var month = "{Content.Date.Format:MM}"; + var day = "{Content.Date.Format:dd}"; + + aliases.Add(Tuple.Create( + pathStart + String.Format("{0}", year), + new RouteValueDictionary { {"area", "Orchard.Blogs"}, {"controller", "BlogPost"}, {"action", "ListByArchive"}, - {"blogId", content.Id}, + {"blogId", content.As().Container.Id}, {"archiveData", String.Format("{0}",year)} })); - aliases.Add(Tuple.Create( - path+String.Format("/Archive/{0}/{1}",year,month), - new RouteValueDictionary { + aliases.Add(Tuple.Create( + pathStart + String.Format("{0}/{1}", year, month), + new RouteValueDictionary { {"area", "Orchard.Blogs"}, {"controller", "BlogPost"}, {"action", "ListByArchive"}, - {"blogId", content.Id}, - {"archiveData", String.Format("{0}/{2}",year,month)} + {"blogId", content.As().Container.Id}, + {"archiveData", String.Format("{0}/{1}",year,month)} })); - aliases.Add(Tuple.Create( - path+String.Format("/Archive/{0}/{1}/{2}",year,month,day), - new RouteValueDictionary { + aliases.Add(Tuple.Create( + pathStart + String.Format("{0}/{1}/{2}", year, month, day), + new RouteValueDictionary { {"area", "Orchard.Blogs"}, {"controller", "BlogPost"}, {"action", "ListByArchive"}, - {"blogId", content.Id}, + {"blogId", content.As().Container.Id}, {"archiveData", String.Format("{0}/{1}/{2}",year,month,day)} })); + } } } } \ No newline at end of file