This code provides a utility for generating slugs from text input within OutSystems applications. Slugs are typically used in URLs to create user-friendly and SEO-friendly web addresses.
The GenerateSlug function performs the following tasks:
GenerateSlug
It takes a string as input and converts it into a slug format, which typically consists of lowercase characters, hyphens to replace spaces, and the removal of special characters.
It uses the Unidecode function to transliterate any accented or non-ASCII characters to their closest ASCII equivalents. For example, it replaces characters like "é" with "e" and "ç" with "c."
Unidecode
If the input string contains the character "º" (the degree symbol), it replaces it with "o" to ensure that it is handled correctly. This is particularly useful for cases where the degree symbol may be used instead of the letter "o."
It removes any remaining special characters, except for hyphens, spaces, and tildes, using regular expressions.
It replaces consecutive spaces with hyphens and removes any duplicated hyphens to ensure the resulting slug is clean and readable.
Finally, it converts the slug to lowercase.
This code is designed to improve the handling of special characters and provide more consistent slugs for URLs in OutSystems applications.