mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-22 20:13:50 +08:00
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:
@@ -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);
|
||||
|
@@ -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",
|
||||
|
@@ -1,4 +1,3 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Models.ViewModels;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
|
Reference in New Issue
Block a user