Files
slp-modular-cms/src/SlpModularCms.Modules.Offerings/Services/Slugifier.cs
T
SluijsensandClaude Sonnet 5 cc09b46cfb
Continuous Integration / config (pull_request) Successful in 12s
Continuous Integration / changes (pull_request) Successful in 21s
Continuous Integration / frontend-prepare (pull_request) Skipped
Continuous Integration / frontend-build (pull_request) Skipped
Continuous Integration / frontend-test (pull_request) Skipped
Continuous Integration / frontend-lint (pull_request) Skipped
Continuous Integration / backend-build (pull_request) Successful in 4m31s
Continuous Integration / vulnerability-scan (pull_request) Successful in 3m57s
Continuous Integration / backend-test (pull_request) Successful in 6m11s
Continuous Integration / publish-production (pull_request) Skipped
Continuous Integration / deploy-production (pull_request) Skipped
Continuous Integration / publish-test (pull_request) Successful in 5m51s
Continuous Integration / deploy-test (pull_request) Skipped
Voeg leesbare slug toe aan Offering naast het GUID-ID
Het Offering-ID is een GUID en niet geschikt om aan gebruikers te tonen.
Voeg een op de titel gebaseerde, unieke slug toe die via de public en
admin API wordt meegegeven, zodat de frontend iets leesbaars kan tonen
in plaats van het ruwe ID. Het ID blijft ongewijzigd de echte identifier.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-04 11:31:16 +02:00

41 lines
1.2 KiB
C#

using System.Text;
namespace SlpModularCms.Modules.Offerings.Services;
/// <summary>
/// Turns a title into a URL/display-safe slug (lowercase, hyphen-separated, no diacritics).
/// Pure string transform — uniqueness is handled by the caller.
/// </summary>
public static class Slugifier
{
public static string Slugify(string value)
{
var normalized = value.Normalize(NormalizationForm.FormD);
var builder = new StringBuilder(normalized.Length);
var lastWasHyphen = false;
foreach (var c in normalized)
{
var category = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(c);
if (category == System.Globalization.UnicodeCategory.NonSpacingMark)
continue;
if (char.IsLetterOrDigit(c))
{
builder.Append(char.ToLowerInvariant(c));
lastWasHyphen = false;
}
else if (!lastWasHyphen && builder.Length > 0)
{
builder.Append('-');
lastWasHyphen = true;
}
}
if (lastWasHyphen)
builder.Length--;
return builder.Length > 0 ? builder.ToString() : "pakket";
}
}