Url.appendSlug
appendSlug($pageTitle, $skipWords='') -> string
Description
Convert $pageTitle
to a slug and append it to the URL path.
A “slug” is a token that is added to a URL to make it more human-readable and optimized for search engines.
See also String.toUrlSlug().
url'/blog'.appendSlug('Learn HTML in 33 Days!') //= url'/blog/learn-html-in-33-days' url'/article'.appendSlug('Turtles & Tide Pools') //= url'/article/turtles-tide-pools'
Skip Words
The $skipWords
argument takes a string containing a space-delimited list of words to exclude from the slug.
This will also filter out any duplicate words from the slug.
$pageTitle = ''' THT News: The THT Festival Was a Success! ''' url'/news'.appendSlug($pageTitle, 'a an the') //= url'/news/tht-news-festival-was-success'
If $skipWords
is :common
, it will be set to a list of about 50 common English words (e.g. 'and', 'or', 'a', etc.) that will result in a cleaner, keyword-dense slug.
$pageTitle = ''' This Man Watched 'Lord of the Rings' 3,000 Times ''' url'/news'.appendSlug($pageTitle, ':common') //= url'/news/man-watched-lord-rings-3000-times'