سلام.
من هم چند متد الحاقی داشتم که مرتبط با SEO اند، البته حتما قابل رشد هست ...
من هم چند متد الحاقی داشتم که مرتبط با SEO اند، البته حتما قابل رشد هست ...
public class SEO { private const char TitleCharSeparator = '-'; //------------------------------------------------- public static string GetTitle(params string[] crumbs) { var maxLenghtTitle = 60; var title = ""; try { foreach (var crumb in crumbs) { title += string.Format(" {0} {1}", TitleCharSeparator, crumb); } title = title.Substring(3); } catch { } title = title.Substring(0, title.Length <= maxLenghtTitle ? title.Length : maxLenghtTitle).Trim(); return title; } //------------------------------------------------- public static string GenerateMetaTag(this string pageTitle, string pageDescription) { var maxLenghtTitle = 60; var maxLenghtDescription = 170; pageTitle = pageTitle.Substring(0, pageTitle.Length <= maxLenghtTitle ? pageTitle.Length : maxLenghtTitle).Trim(); pageDescription = pageDescription.Substring(0, pageDescription.Length <= maxLenghtDescription ? pageDescription.Length : maxLenghtDescription).Trim(); var meta = ""; try { meta += string.Format("<title>{0}</title>\n", pageTitle); meta += string.Format("<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"); meta += string.Format("<meta charset=\"utf-8\"/>\n"); meta += string.Format("<meta name=\"description\" content=\"{0}\"/>\n", pageDescription); meta += string.Format("<meta name=\"robots\" content=\"{0}\" />\n", "follow"); meta += string.Format("<link rel=\"shortcut icon\" href=\"{0}\"/>\n", "~/cdn/images/ui/favicon.ico"); } catch { } return meta; } //------------------------------------------------- public static string GenerateSlug(this string title) { var maxLenghtSlug = 45; string str = title.RemoveAccent().ToLower();
str = Regex.Replace(str, @"[^a-z0-9-\u0600-\u06FF]", "-"); str = Regex.Replace(str, @"\s+", "-").Trim(); str = Regex.Replace(str, @"-+", "-"); str = str.Substring(0, str.Length <= maxLenghtSlug ? str.Length : maxLenghtSlug).Trim();
return str; } //------------------------------------------------- private static string RemoveAccent(this string txt) { var bytes = Encoding.GetEncoding("UTF-8").GetBytes(txt); return Encoding.UTF8.GetString(bytes); } //------------------------------------------------- }