From ad652b724dae4f0d4d59f55fbaa0de0196ba45bf Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 21 Feb 2014 14:30:47 -0800 Subject: [PATCH] Adding blog/archive route --- .../Controllers/BlogPostController.cs | 9 +++- .../Routing/ArchiveConstraint.CS | 45 ++++++++++++++++++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs index 1e6344388..73e79af07 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogPostController.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Web.Mvc; using Orchard.Blogs.Extensions; @@ -7,6 +8,7 @@ using Orchard.Blogs.Services; using Orchard.Core.Feeds; using Orchard.DisplayManagement; using Orchard.Localization; +using Orchard.Mvc; using Orchard.Themes; namespace Orchard.Blogs.Controllers { @@ -49,10 +51,15 @@ namespace Orchard.Blogs.Controllers { return HttpNotFound(); BlogPart blogPart = _blogService.Get(blogPath); - if (blogPart == null) return HttpNotFound(); + + if (archive.ToDateTime() == DateTime.MinValue) { + // render the archive data + return new ShapeResult(this, Shape.Parts_Blogs_BlogArchives(Blog: blogPart, Archives: _blogPostService.GetArchives(blogPart))); + } + var list = Shape.List(); list.AddRange(_blogPostService.Get(blogPart, archive).Select(b => _services.ContentManager.BuildDisplay(b, "Summary"))); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS index 20d30d7b5..f1617a781 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routing/ArchiveConstraint.CS @@ -46,10 +46,31 @@ namespace Orchard.Blogs.Routing { } public string FindPath(string path) { + // my-blog/archive + if (path.EndsWith("/archive")) { + return path.Substring(0, path.Length - "/archive".Length); + } + + // my-blog/archive/ + if (path.EndsWith("/archive/")) { + return null; + } + + // my-blog/archive/2014 var archiveIndex = path.IndexOf("/archive/", StringComparison.OrdinalIgnoreCase); if (archiveIndex == -1) { - + + // archive/ + if (path.EndsWith("archive/")) { + return null; + } + + // archive + if (path.EndsWith("archive")) { + return String.Empty; + } + // archive for blog as homepage ? if(path.StartsWith("archive/", StringComparison.OrdinalIgnoreCase)) { return String.Empty; @@ -62,10 +83,30 @@ namespace Orchard.Blogs.Routing { } public ArchiveData FindArchiveData(string path) { + // my-blog/archive + if (path.EndsWith("/archive")) { + return new ArchiveData(""); + } + + // my-blog/archive/ + if (path.EndsWith("/archive/")) { + return null; + } + var archiveIndex = path.IndexOf("/archive/", StringComparison.OrdinalIgnoreCase); if (archiveIndex == -1) { - + + // archive/ + if (path.EndsWith("archive/")) { + return null; + } + + // archive + if (path.EndsWith("archive")) { + return new ArchiveData(""); + } + // archive for blog as homepage ? if (path.StartsWith("archive/", StringComparison.OrdinalIgnoreCase)) { return new ArchiveData(path.Substring("archive/".Length));