Documentation
¶
Overview ¶
Package slug provides URL-safe slug generation from strings.
It handles Unicode transliteration, configurable separators, max length truncation at word boundaries, and unique slug generation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*Slugger)
Option configures a Slugger.
func WithCustomSubs ¶
WithCustomSubs sets custom string substitutions that are applied before transliteration. Keys are matched case-sensitively.
func WithMaxLen ¶
WithMaxLen sets the maximum length of the generated slug. The slug is truncated at the last word boundary (separator) before maxLen. A value of 0 means no limit.
func WithSeparator ¶
WithSeparator sets the separator character used between words. The default separator is "-".
type Slugger ¶
type Slugger struct {
// contains filtered or unexported fields
}
Slugger generates URL-safe slugs with configurable options.
func (*Slugger) Make ¶
Make generates a URL-safe slug from the given string.
The algorithm is:
- Apply custom substitutions
- Transliterate Unicode to ASCII
- Lowercase
- Replace any non [a-z0-9] with separator
- Collapse consecutive separators
- Trim separators from start/end
- If maxLen is set, truncate at word boundary