|
|
MvcCms Automatically Creates URL Slugs
A URL slug is a SEO- and user-friendly string-part in a URL to identify, describe and access a resource. Often the title of a page/article is a valid candidate. For example the title of this page is "URL Slug" which contains a space. MvcCms has automatically changed the title to url-slug to place in the URL of the page. Navigation links are automatically set to use the url-slug generated as the link and the title as typed in "URL Slug" as the anchor text.
One way to think of MvcCms at its core is as a semantic assembly engine. We have taken the concept of content categories and pages and create references to the combination of...
category+?subcategory(?multiple)+?page
The ? symbol indicates that the url piece following it is allowed to be null or empty. Subcategories have unlimited nesting.
URL slugs created from titles map to a specific content page stored in the database behind the scenes.
There have to be some rules to this though or routes could become overlapped from duplication. These rules allow for an entire site to have semantically driven URL's without any of the id query string clutter.
The rules we have designed are:
1.When you create a content category the URL slug created from the title is checked against all other slugs (paths) created for categories and if a match is found the insert is canceled and the user is prompted to revise.
2. When you create a content page all the other paths in that category are checked and if a match is found the insert is cancelled and the user is prompted to revise.
A snippet of this core logic is below, from MvcCms.Core/MvcCmsValidation.cs:
var currentPortal = _cacheService.GetCurrentPortal();
//find out if path already exists
ContentCategory cat2Check = _repository.GetContentCategoryByFullPath(categoryToValidate.Path,
categoryToValidate.Portal);
if (cat2Check != null && cat2Check.CategoryID != categoryToValidate.CategoryID)
{
message="The path from title '" + categoryToValidate.Path +
"' is already being used, please adjust your title.";
return false;
}
if (categoryToValidate.ParentCategory != null)
{
//find out if page path exists in this category
IEnumerable<ContentPage> pages = _repository
.ListPagesByCat(categoryToValidate.ParentCategory.CategoryID, currentPortal);
foreach (ContentPage page in pages)
{
if (page.Path == categoryToValidate.SinglePath)
{
message="The path from title '" + categoryToValidate.Path +
"' already exists as a page for the parent category, please revise to save the page.";
return false;
}
}
}
return true;
Please wait...

Please wait...


You must be Loged On to make a comment.