Added Slugify action to be used in client script for setting the post slug based on the title of the post.

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043168
This commit is contained in:
ErikPorter
2009-12-04 07:25:42 +00:00
parent e61105b799
commit 4e93b3e601
3 changed files with 37 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
using System.Text.RegularExpressions;
using System.Web.Mvc;
using Orchard.Blogs.Extensions;
using Orchard.Blogs.Models;
@@ -63,6 +64,28 @@ namespace Orchard.Blogs.Controllers {
return View(new BlogPostViewModel { Blog = blog, Post = post, ItemView = _contentManager.GetDisplayViewModel(post.ContentItem, null, "detail") });
}
public ActionResult Slugify(string value) {
string slug = value;
if (!string.IsNullOrEmpty(value)) {
Regex regex = new Regex("([^a-z0-9-_]?)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
slug = value.Trim();
slug = slug.Replace(' ', '-');
slug = slug.Replace("---", "-");
slug = slug.Replace("--", "-");
slug = regex.Replace(slug, "");
if (slug.Length * 2 < value.Length)
return Json("");
if (slug.Length > 100)
slug = slug.Substring(0, 100);
}
return Json(slug);
}
public ActionResult Create(string blogSlug) {
//TODO: (erikpo) Move looking up the current blog up into a modelbinder
Blog blog = _blogService.Get(blogSlug);

View File

@@ -21,6 +21,20 @@ namespace Orchard.Blogs {
public IEnumerable<RouteDescriptor> GetRoutes() {
return new[] {
new RouteDescriptor {
Route = new Route(
"Admin/Blogs/Slugify",
new RouteValueDictionary {
{"area", "Orchard.Blogs"},
{"controller", "BlogPost"},
{"action", "Slugify"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "Orchard.Blogs"}
},
new MvcRouteHandler())
},
new RouteDescriptor {
Route = new Route(
"Admin/Blogs/Create",

View File

@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Orchard.Blogs.Models;
using Orchard.Models.ViewModels;
using Orchard.Mvc.ViewModels;