|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using Slugify; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using Unidecode.NET; |
|
|
|
|
|
|
|
namespace Volo.CmsKit.Blogs.Extensions |
|
|
|
@ -7,24 +8,9 @@ namespace Volo.CmsKit.Blogs.Extensions |
|
|
|
{ |
|
|
|
public static string NormalizeAsUrlSlug(this string value) |
|
|
|
{ |
|
|
|
value = value.ToLowerInvariant(); |
|
|
|
var slugHelper = new SlugHelper(); |
|
|
|
|
|
|
|
// Unidecode for non-latin characters
|
|
|
|
value = value.Unidecode(); |
|
|
|
|
|
|
|
// Replace spaces
|
|
|
|
value = Regex.Replace(value, @"\s", "-", RegexOptions.Compiled); |
|
|
|
|
|
|
|
// Remove invalid chars
|
|
|
|
value = Regex.Replace(value, @"[^a-z0-9\s-_]", "", RegexOptions.Compiled); |
|
|
|
|
|
|
|
// Trim dashes & dots
|
|
|
|
value = value.Trim('-', '_', '.'); |
|
|
|
|
|
|
|
// Replace double occurences of - or _
|
|
|
|
value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled); |
|
|
|
|
|
|
|
return value; |
|
|
|
return slugHelper.GenerateSlug(value); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|