|
|
|
@ -1,5 +1,6 @@ |
|
|
|
using JetBrains.Annotations; |
|
|
|
using System; |
|
|
|
using System.Text.RegularExpressions; |
|
|
|
using Volo.Abp; |
|
|
|
using Volo.Abp.Domain.Entities.Auditing; |
|
|
|
using Volo.CmsKit.Blogs; |
|
|
|
@ -45,7 +46,9 @@ namespace Volo.CmsKit.Domain.Volo.CmsKit.Blogs |
|
|
|
|
|
|
|
public void SetUrlSlug(string urlSlug) |
|
|
|
{ |
|
|
|
UrlSlug = Check.NotNullOrWhiteSpace(urlSlug, nameof(urlSlug), BlogPostConsts.MaxUrlSlugLength, BlogPostConsts.MinUrlSlugLength); |
|
|
|
Check.NotNullOrWhiteSpace(urlSlug, nameof(urlSlug), BlogPostConsts.MaxUrlSlugLength, BlogPostConsts.MinUrlSlugLength); |
|
|
|
|
|
|
|
UrlSlug = NormalizeUrlSlug(urlSlug); |
|
|
|
} |
|
|
|
|
|
|
|
public void SetIsPublished(bool isPublished) |
|
|
|
@ -57,5 +60,27 @@ namespace Volo.CmsKit.Domain.Volo.CmsKit.Blogs |
|
|
|
|
|
|
|
IsPublished = IsPublished; |
|
|
|
} |
|
|
|
|
|
|
|
private string NormalizeUrlSlug(string value) |
|
|
|
{ |
|
|
|
value = value.ToLowerInvariant(); |
|
|
|
|
|
|
|
// TODO: Find best way to unidecode.
|
|
|
|
// 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 from end & dots
|
|
|
|
value = value.Trim('-', '_', '.'); |
|
|
|
|
|
|
|
// Replace double occurences of - or _
|
|
|
|
value = Regex.Replace(value, @"([-_]){2,}", "$1", RegexOptions.Compiled); |
|
|
|
|
|
|
|
return value; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|