-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement URL slugs for Users and Slots * Fix extra spaces in slot slugs
- Loading branch information
Showing
8 changed files
with
55 additions
and
8 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
ProjectLighthouse.Servers.Website/Extensions/SlugExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Text.RegularExpressions; | ||
using System.Web; | ||
using LBPUnion.ProjectLighthouse.Types.Entities.Level; | ||
using LBPUnion.ProjectLighthouse.Types.Entities.Profile; | ||
|
||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Extensions; | ||
|
||
public static partial class SlugExtensions | ||
{ | ||
[GeneratedRegex("[^a-zA-Z0-9 ]")] | ||
private static partial Regex ValidSlugCharactersRegex(); | ||
|
||
[GeneratedRegex(@"[\s]{2,}")] | ||
private static partial Regex WhitespaceRegex(); | ||
|
||
/// <summary> | ||
/// Generates a URL slug that only contains alphanumeric characters | ||
/// with spaces replaced with dashes | ||
/// </summary> | ||
/// <param name="slot">The slot to generate the slug for</param> | ||
/// <returns>A string containing the url slug for this slot</returns> | ||
public static string GenerateSlug(this SlotEntity slot) => | ||
slot.Name.Length == 0 | ||
? "unnamed-level" | ||
: WhitespaceRegex().Replace(ValidSlugCharactersRegex().Replace(HttpUtility.HtmlDecode(slot.Name), ""), " ").Replace(" ", "-").ToLower(); | ||
|
||
/// <summary> | ||
/// Generates a URL slug for the given user | ||
/// </summary> | ||
/// <param name="user">The user to generate the slug for</param> | ||
/// <returns>A string containing the url slug for this user</returns> | ||
public static string GenerateSlug(this UserEntity user) => user.Username.ToLower(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters