mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Blog pattern descriptors
--HG-- branch : autoroute
This commit is contained in:
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
ffba6aa744a1153e5ba4324a5f8fe70da45b2bb8 src/Orchard.Web/Modules/Orchard.Alias
|
ffba6aa744a1153e5ba4324a5f8fe70da45b2bb8 src/Orchard.Web/Modules/Orchard.Alias
|
||||||
ce36031536b78ee9767801c720c142f3c515f2d0 src/Orchard.Web/Modules/Orchard.Autoroute
|
2f2f0961b1836c0813838c8d184f29041ca11175 src/Orchard.Web/Modules/Orchard.Autoroute
|
||||||
67bf9897ee9dd9483369aece729ad7c6f042941c src/Orchard.Web/Modules/Orchard.Forms
|
67bf9897ee9dd9483369aece729ad7c6f042941c src/Orchard.Web/Modules/Orchard.Forms
|
||||||
1d093e0b3327ecd5851a878e1eb6c64fbd683e05 src/Orchard.Web/Modules/Orchard.Projections
|
1d093e0b3327ecd5851a878e1eb6c64fbd683e05 src/Orchard.Web/Modules/Orchard.Projections
|
||||||
a1ef39ba4e2d0cd78b3c91d6150e841793acb34b src/Orchard.Web/Modules/Orchard.Routable
|
a1ef39ba4e2d0cd78b3c91d6150e841793acb34b src/Orchard.Web/Modules/Orchard.Routable
|
||||||
75b2107eb093154b35832e3ea6e8514d4a66426a src/Orchard.Web/Modules/Orchard.Rules
|
75b2107eb093154b35832e3ea6e8514d4a66426a src/Orchard.Web/Modules/Orchard.Rules
|
||||||
ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease
|
ce578373f907c0a55fd91229a344f0755f290174 src/Orchard.Web/Modules/Orchard.TaskLease
|
||||||
df77a7a8dbd846eb1f3af04a5ab4ca17ab0b8d9f src/Orchard.Web/Modules/Orchard.Tokens
|
28251b07a1c122ff34c0aa9c05cd8c8fce9b3c7a src/Orchard.Web/Modules/Orchard.Tokens
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Orchard.Blogs.Handlers {
|
|||||||
if (blogPost == null)
|
if (blogPost == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Note: DisplayRouteValues are simply inherited from CommonPart
|
// Note: DisplayRouteValues are still inherited from CommonPart. We shouldn't even need these overrides for admin routes. -PH
|
||||||
|
|
||||||
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
context.Metadata.CreateRouteValues = new RouteValueDictionary {
|
||||||
{"Area", "Orchard.Blogs"},
|
{"Area", "Orchard.Blogs"},
|
||||||
|
|||||||
@@ -135,6 +135,10 @@
|
|||||||
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
<Project>{9916839C-39FC-4CEB-A5AF-89CA7E87119F}</Project>
|
||||||
<Name>Orchard.Core</Name>
|
<Name>Orchard.Core</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
|
<ProjectReference Include="..\Orchard.Autoroute\Orchard.Autoroute.csproj">
|
||||||
|
<Project>{66FCCD76-2761-47E3-8D11-B45D0001DDAA}</Project>
|
||||||
|
<Name>Orchard.Autoroute</Name>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Placement.info">
|
<Content Include="Placement.info">
|
||||||
|
|||||||
@@ -7,72 +7,84 @@ using System.Web.Routing;
|
|||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.Blogs.Models;
|
using Orchard.Blogs.Models;
|
||||||
using Orchard.Core.Common.Models;
|
using Orchard.Core.Common.Models;
|
||||||
|
using Orchard.Autoroute.Services;
|
||||||
|
using Orchard.Localization;
|
||||||
|
|
||||||
namespace Orchard.Blogs.Routing {
|
namespace Orchard.Blogs.Routing {
|
||||||
public interface IRoutePatternProvider : IEventHandler {
|
|
||||||
void Routed(IContent content, String path, ICollection<Tuple<string, RouteValueDictionary>> aliases);
|
|
||||||
}
|
|
||||||
public class BlogAutoroutes : IRoutePatternProvider {
|
public class BlogAutoroutes : IRoutePatternProvider {
|
||||||
|
|
||||||
public void Routed(IContent content, string path, ICollection<Tuple<string, RouteValueDictionary>> aliases) {
|
public BlogAutoroutes() {
|
||||||
|
T = NullLocalizer.Instance;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: (PH:Autoroute) Cheap and it works. But could there be a better way?
|
public Localizer T { get; set; }
|
||||||
if (content.Is<BlogPart>()) {
|
|
||||||
// Add RSD route
|
const string yearToken = "{Content.Date.Format:yyyy}";
|
||||||
aliases.Add(Tuple.Create(
|
const string monthToken = "{Content.Date.Format:MM}";
|
||||||
path + "/rsd",
|
const string dayToken = "{Content.Date.Format:dd}";
|
||||||
new RouteValueDictionary {{"area", "Orchard.Blogs"},
|
const string idParentToken = "{Content.Container.Id}";
|
||||||
|
const string idToken = "{Content.Id}";
|
||||||
|
const string blogToken = "{Content.Slug}";
|
||||||
|
const string blogPostToken = "{Content.Container.Path}/{Content.Slug}";
|
||||||
|
|
||||||
|
public void Describe(DescribePatternContext describe) {
|
||||||
|
// TODO: (PH) Could implement RSD for non-blog content much more easily now the routing can be applied to any content item... (maybe need a RemotePublishingPart?)
|
||||||
|
// TODO: Must restrict these to appropriate parts/types...
|
||||||
|
describe.For("Content")
|
||||||
|
// .Where<IContent>(c => c.Is<BlogPart>())
|
||||||
|
.Pattern("Rsd", T("Remote Blog Publishing"), T("Remote Blog Publishing destination Url"),
|
||||||
|
new RouteValueDictionary {
|
||||||
|
{"area", "Orchard.Blogs"},
|
||||||
{"controller", "RemoteBlogPublishing"},
|
{"controller", "RemoteBlogPublishing"},
|
||||||
{"action", "Rsd"},
|
{"action", "Rsd"},
|
||||||
{"blogId", content.Id}
|
{"blogId", idToken}})
|
||||||
}));
|
.Pattern("Archive", T("Blog Archives"), T("Displays a list of all blog archives"),
|
||||||
aliases.Add(Tuple.Create(
|
|
||||||
path + "/Archive",
|
|
||||||
new RouteValueDictionary {
|
new RouteValueDictionary {
|
||||||
{"area", "Orchard.Blogs"},
|
{"area", "Orchard.Blogs"},
|
||||||
{"controller", "BlogPost"},
|
{"controller", "BlogPost"},
|
||||||
{"action", "ListByArchive"},
|
{"action", "ListByArchive"},
|
||||||
{"blogId", content.Id},
|
{"blogId", idToken},
|
||||||
{"archiveData", ""}
|
{"archiveData", ""}
|
||||||
}));
|
})
|
||||||
}
|
;
|
||||||
|
describe.For("Content")
|
||||||
if (content.Is<BlogPostPart>()) {
|
// .Where<IContent>(c => c.Is<BlogPostPart>())
|
||||||
var pathStart = "{Content.Container.Slug}/Archive/";
|
.Pattern("ArchiveYear", T("Blog Archives by Year"), T("Displays a list of all blog archives for a particular year"),
|
||||||
|
|
||||||
// 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 {
|
new RouteValueDictionary {
|
||||||
{"area", "Orchard.Blogs"},
|
{"area", "Orchard.Blogs"},
|
||||||
{"controller", "BlogPost"},
|
{"controller", "BlogPost"},
|
||||||
{"action", "ListByArchive"},
|
{"action", "ListByArchive"},
|
||||||
{"blogId", content.As<CommonPart>().Container.Id},
|
{"blogId", idParentToken},
|
||||||
{"archiveData", String.Format("{0}",year)}
|
{"archiveData", String.Format("{0}",yearToken)}
|
||||||
}));
|
})
|
||||||
aliases.Add(Tuple.Create(
|
.Pattern("ArchiveMonth", T("Blog Archives by Month"), T("Displays a list of all blog archives for a particular year and month"),
|
||||||
pathStart + String.Format("{0}/{1}", year, month),
|
|
||||||
new RouteValueDictionary {
|
new RouteValueDictionary {
|
||||||
{"area", "Orchard.Blogs"},
|
{"area", "Orchard.Blogs"},
|
||||||
{"controller", "BlogPost"},
|
{"controller", "BlogPost"},
|
||||||
{"action", "ListByArchive"},
|
{"action", "ListByArchive"},
|
||||||
{"blogId", content.As<CommonPart>().Container.Id},
|
{"blogId", idParentToken},
|
||||||
{"archiveData", String.Format("{0}/{1}",year,month)}
|
{"archiveData", String.Format("{0}/{1}",yearToken,monthToken)}
|
||||||
}));
|
})
|
||||||
aliases.Add(Tuple.Create(
|
.Pattern("ArchiveDay", T("Blog Archives by Day"), T("Displays a list of all blog archives for a particular date"),
|
||||||
pathStart + String.Format("{0}/{1}/{2}", year, month, day),
|
|
||||||
new RouteValueDictionary {
|
new RouteValueDictionary {
|
||||||
{"area", "Orchard.Blogs"},
|
{"area", "Orchard.Blogs"},
|
||||||
{"controller", "BlogPost"},
|
{"controller", "BlogPost"},
|
||||||
{"action", "ListByArchive"},
|
{"action", "ListByArchive"},
|
||||||
{"blogId", content.As<CommonPart>().Container.Id},
|
{"blogId", idParentToken},
|
||||||
{"archiveData", String.Format("{0}/{1}/{2}",year,month,day)}
|
{"archiveData", String.Format("{0}/{1}/{2}",yearToken,monthToken,dayToken)}
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public void Suggest(SuggestPatternContext suggest) {
|
||||||
|
suggest.For("Content")
|
||||||
|
.Suggest("Rsd", "blog-title/rsd", blogToken + "/rsd", T("Rsd is a sub-path of the blog post"))
|
||||||
|
.Suggest("Archives", "blog-title/archives", blogToken + "/archives", T("Archives is a sub-path of the blog post"))
|
||||||
|
.Suggest("View", "blog-title", blogToken, T("Blog title"))
|
||||||
|
.Suggest("View", "blog-title/post-title", blogPostToken, T("Nested blog/post path"))
|
||||||
|
.Suggest("ArchivesYear", "blog-title/post-title/archives/yy", String.Format("{0}/archives/{1}",blogPostToken,yearToken), T("Archives year"))
|
||||||
|
.Suggest("ArchivesMonth", "blog-title/post-title/archives/yy/mm", String.Format("{0}/archives/{1}/{2}",blogPostToken,yearToken,monthToken), T("Archives year/month"))
|
||||||
|
.Suggest("ArchivesDay", "blog-title/post-title/archives/yy/mm/dd", String.Format("{0}/archives/{1}/{2}/{3}", blogPostToken, yearToken,monthToken,dayToken), T("Archives year/month/day"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user